Setup¶

Install in R:

install.packages("BiocManager")
BiocManager::install(c("edgeR", "BiocParallel", "RhpcBLASctl"))

Install

pip install toytree ete4 pybiomart

Options & Data¶

In [ ]:
%load_ext autoreload
%autoreload 2

import os
import re
import pickle
import matplotlib.pyplot as plt
import warnings
import logging
import seaborn as sns
from scipy.sparse import issparse
from pymer4.models import lmer, lm, glmer, compare
from pymer4 import config
import polars
import statsmodels.api as sm
import senepy
import gseapy as gp
import pertpy as pt
import scanpy as sc
import pandas as pd
import numpy as np
import scflow
from scflow.ax import find_senescence_genes, run_senepy

# Display/Environment Settings
os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
warnings.filterwarnings("ignore", message=".*ast.Ellipsis is deprecated.*")
config.PANDAS_BACKEND = True
warnings.filterwarnings("ignore", message=".*vert.*will be deprecated.*")
pd.set_option("display.max_rows", 500)  # or None for unlimited rows
pd.set_option("display.max_columns", 100)
pd.set_option("display.max_colwidth", 100)
pd.set_option("display.width", 300)
warnings.filterwarnings(
    "ignore", message="Bitwise inversion '~' on bool is deprecated",
    category=DeprecationWarning)

# Process Options
ncpus = os.cpu_count() - 1
overwrite = True

# If You Want Results Emailed (Will Overwrite HTML Regardless of `overwite`)
cur_file = os.path.join(os.path.abspath(""), "analyze_senescence_celltype_"
                        "specific_threshold_SRR23052428.ipynb")
html_out = os.path.splitext(cur_file)[0] + ".html"
email = "elizabeth.aslinger@aya.yale.edu"
# set email to None to skip

# Metadata Information
col_celltype = "annotation_by_overlap"
species = "Mouse"
col_sample, col_batch = "sample", "Condition"
col_condition = "Condition"
keys = {col_condition: dict(key_control="Control",
                            key_treatment="Irradiated")}
palette = {keys[col_condition]["key_control"]: "c",
           keys[col_condition]["key_treatment"]: "tab:pink"}
palette = {col_batch: palette, col_condition: palette}

# Scoring Metrics
sen_metrics = ["senmayo"]
use_metric = "senmayo"
percentile = 1

# File Input & Output
file_path = "data/SRR23052428_SRR23052429_integrated.h5ad"
file_path_new = os.path.splitext(file_path)[0] + "_analyzed.h5ad"

# Load Data
self = scflow.Rna(file_path, col_sample=col_sample,
                  col_celltype=col_celltype, col_batch=col_batch)

# Display Object
print(self.rna)
self.rna.obs
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/senepy/load_hubs.py:3: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  from pkg_resources import resource_filename
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/marshmallow/__init__.py:17: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  __version_info__ = tuple(LooseVersion(__version__).version)
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/marshmallow/fields.py:198: RemovedInMarshmallow4Warning: Passing field metadata as a keyword arg is deprecated. Use the explicit `metadata=...` argument instead.
  warnings.warn(
AnnData object with n_obs × n_vars = 31446 × 23253
    obs: 'sample', 'n_cells_original_sample', 'Condition', 'kws_pp_sample', 'n_genes_by_counts', 'total_counts', 'log1p_n_genes_by_counts', 'log1p_total_counts', 'total_counts_mt', 'pct_counts_mt', 'log1p_total_counts_mt', 'total_counts_ribo', 'pct_counts_ribo', 'log1p_total_counts_ribo', 'total_counts_hb', 'pct_counts_hb', 'log1p_total_counts_hb', 'n_counts', 'n_genes', 'doublet_score', 'predicted_doublet', 'leiden_individual_res0.15dist0.15', 'annotation_by_markers_individual_res0.15dist0.15', 'annotation_by_markers_individual_heterogeneous_collapsed', 'leiden_individual', 'annotation_by_markers_individual', 'kws_cluster_individual', 'annotation_scanvi', 'kws_integrate', 'leiden', 'leiden_resolution', 'leiden_n_neighbors', 'leiden_min_dist', 'annotation_by_overlap', 'leiden_subcluster', 'resolution_leiden_subcluster', 'annotation_toppgene', 'predicted_labels', 'majority_voting', 'majority_voting_probabilities', 'annotation_predicted_labels', 'annotation_majority_voting'
    var: 'gene_ids', 'feature_types', 'mt', 'ribo', 'hb', 'highly_variable', 'means', 'dispersions', 'dispersions_norm', 'mean', 'std', 'n_cells_by_counts', 'total_counts', 'mean_counts', 'pct_dropout_by_counts', 'log1p_total_counts', 'log1p_mean_counts'
    uns: 'Condition_colors', 'annotation_by_overlap_colors', 'annotation_majority_voting_colors', 'annotation_predicted_labels_colors', 'annotation_scanvi_colors', 'annotation_toppgene_colors', 'hvg', 'leiden', 'leiden_colors', 'leiden_subcluster', 'leiden_subcluster_colors', 'log1p', 'neighbors', 'over_clustering', 'rank_genes_groups_leiden', 'rank_genes_groups_leiden_subcluster', 'sample_colors', 'umap'
    obsm: 'X_pca', 'X_pca_old', 'X_scANVI', 'X_umap'
    layers: 'counts', 'log1p', 'scaled'
    obsp: 'connectivities', 'distances'
Out[ ]:
sample n_cells_original_sample Condition kws_pp_sample n_genes_by_counts total_counts log1p_n_genes_by_counts log1p_total_counts total_counts_mt pct_counts_mt log1p_total_counts_mt total_counts_ribo pct_counts_ribo log1p_total_counts_ribo total_counts_hb pct_counts_hb log1p_total_counts_hb n_counts n_genes doublet_score predicted_doublet leiden_individual_res0.15dist0.15 annotation_by_markers_individual_res0.15dist0.15 annotation_by_markers_individual_heterogeneous_collapsed leiden_individual annotation_by_markers_individual kws_cluster_individual annotation_scanvi kws_integrate leiden leiden_resolution leiden_n_neighbors leiden_min_dist annotation_by_overlap leiden_subcluster resolution_leiden_subcluster annotation_toppgene predicted_labels majority_voting majority_voting_probabilities annotation_predicted_labels annotation_majority_voting
AAACCCAAGAGTTCGG-1_SRR23052428 SRR23052428 22119 Irradiated {'min_max_genes': [426, None], 'min_max_cells': [3, None], 'max_mt': 5, 'min_max_counts': [581, ... 765 1941.574829 6.641182 7.571770 9.624470 0.495704 2.363160 7.865369 0.405103 2.182153 0.000000 0.000000 0.000000 993.0 767 0.002254 False 3 Pericyte Pericyte 3 Pericyte {'resolution': 0.15, 'min_dist': 0.15, 'n_comps': 50} Pericyte {'col_celltype': 'annotation_by_markers_individual_heterogeneous_collapsed', 'flavor': 'scanvi',... 5 0.05 40 1 Endothelial 5 0.07 Endothelial 331 Peri NN 331 Peri NN 0.992559 Pericyte Pericyte
AAACCCAAGATTGTGA-1_SRR23052428 SRR23052428 22119 Irradiated {'min_max_genes': [426, None], 'min_max_cells': [3, None], 'max_mt': 5, 'min_max_counts': [581, ... 2007 3194.267334 7.604894 8.069426 1.350562 0.042281 0.854654 14.969015 0.468621 2.770650 1.350562 0.042281 0.854654 3499.0 2009 0.041719 False 0 Oligodendrocyte Oligodendrocyte 0 Oligodendrocyte {'resolution': 0.15, 'min_dist': 0.15, 'n_comps': 50} Oligodendrocyte {'col_celltype': 'annotation_by_markers_individual_heterogeneous_collapsed', 'flavor': 'scanvi',... 0 0.05 40 1 Neuron 0,0 0.07 0,0 031 CT SUB Glut Heterogeneous NaN Excitatory Heterogeneous
AAACCCAAGTGCCAGA-1_SRR23052428 SRR23052428 22119 Irradiated {'min_max_genes': [426, None], 'min_max_cells': [3, None], 'max_mt': 5, 'min_max_counts': [581, ... 2399 3327.978516 7.783224 8.110421 1.075810 0.032326 0.730351 18.731564 0.562851 2.982220 0.000000 0.000000 0.000000 5175.0 2399 0.028328 False 7 Inhibitory Inhibitory 7 Inhibitory {'resolution': 0.15, 'min_dist': 0.15, 'n_comps': 50} Inhibitory {'col_celltype': 'annotation_by_markers_individual_heterogeneous_collapsed', 'flavor': 'scanvi',... 0 0.05 40 1 Neuron 0,0 0.07 0,0 049 Lamp5 Gaba 049 Lamp5 Gaba 0.997975 Inhibitory Inhibitory
AAACCCAAGTTGAATG-1_SRR23052428 SRR23052428 22119 Irradiated {'min_max_genes': [426, None], 'min_max_cells': [3, None], 'max_mt': 5, 'min_max_counts': [581, ... 2280 3235.130127 7.732369 8.082133 5.981792 0.184901 1.943306 7.076156 0.218729 2.088916 0.000000 0.000000 0.000000 5032.0 2280 0.021174 False 1 Astrocyte Astrocyte 1 Astrocyte {'resolution': 0.15, 'min_dist': 0.15, 'n_comps': 50} Astrocyte {'col_celltype': 'annotation_by_markers_individual_heterogeneous_collapsed', 'flavor': 'scanvi',... 2 0.05 40 1 Astrocyte 2 0.07 Astrocyte 318 Astro-NT NN 318 Astro-NT NN 0.996337 Astrocyte Astrocyte
AAACCCACAATTCTTC-1_SRR23052428 SRR23052428 22119 Irradiated {'min_max_genes': [426, None], 'min_max_cells': [3, None], 'max_mt': 5, 'min_max_counts': [581, ... 924 2098.277344 6.829794 7.649348 6.093319 0.290396 1.959153 10.780834 0.513794 2.466474 0.000000 0.000000 0.000000 1510.0 924 0.050669 False 9 OPC OPC 9 OPC {'resolution': 0.15, 'min_dist': 0.15, 'n_comps': 50} OPC {'col_celltype': 'annotation_by_markers_individual_heterogeneous_collapsed', 'flavor': 'scanvi',... 4 0.05 40 1 OPC 4 0.07 OPC 326 OPC NN 326 OPC NN 0.020204 OPC OPC
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
TTTGTTGTCGAATGCT-1_SRR23052429 SRR23052429 15125 Control {'min_max_genes': [325, None], 'min_max_cells': [3, None], 'max_mt': 5, 'min_max_counts': [531, ... 1922 2881.593262 7.561642 7.966445 12.326752 0.427776 2.589773 20.215572 0.701541 3.054735 0.000000 0.000000 0.000000 4257.0 1922 0.023757 False 3 Oligodendrocyte Oligodendrocyte 3 Oligodendrocyte {'resolution': 0.15, 'min_dist': 0.15, 'n_comps': 50} Oligodendrocyte {'col_celltype': 'annotation_by_markers_individual_heterogeneous_collapsed', 'flavor': 'scanvi',... 1 0.05 40 1 Oligodendrocyte 1 0.07 Oligodendrocyte 327 Oligo NN 327 Oligo NN 1.000000 Oligodendrocyte Oligodendrocyte
TTTGTTGTCGCTAAAC-1_SRR23052429 SRR23052429 15125 Control {'min_max_genes': [325, None], 'min_max_cells': [3, None], 'max_mt': 5, 'min_max_counts': [531, ... 1614 2719.958252 7.387090 7.908740 1.961062 0.072099 1.085548 17.917770 0.658752 2.940102 1.961062 0.072099 1.085548 3275.0 1614 0.043113 False 3 Oligodendrocyte Oligodendrocyte 3 Oligodendrocyte {'resolution': 0.15, 'min_dist': 0.15, 'n_comps': 50} Oligodendrocyte {'col_celltype': 'annotation_by_markers_individual_heterogeneous_collapsed', 'flavor': 'scanvi',... 1 0.05 40 1 Oligodendrocyte 1 0.07 Oligodendrocyte 327 Oligo NN 327 Oligo NN 0.999996 Oligodendrocyte Oligodendrocyte
TTTGTTGTCTAAGCGT-1_SRR23052429 SRR23052429 15125 Control {'min_max_genes': [325, None], 'min_max_cells': [3, None], 'max_mt': 5, 'min_max_counts': [531, ... 1405 2566.608154 7.248504 7.850730 0.000000 0.000000 0.000000 14.542569 0.566607 2.743583 0.000000 0.000000 0.000000 2690.0 1405 0.031539 False 3 Oligodendrocyte Oligodendrocyte 3 Oligodendrocyte {'resolution': 0.15, 'min_dist': 0.15, 'n_comps': 50} Oligodendrocyte {'col_celltype': 'annotation_by_markers_individual_heterogeneous_collapsed', 'flavor': 'scanvi',... 1 0.05 40 1 Oligodendrocyte 1 0.07 Oligodendrocyte 327 Oligo NN 327 Oligo NN 1.000000 Oligodendrocyte Oligodendrocyte
TTTGTTGTCTGCCTGT-1_SRR23052429 SRR23052429 15125 Control {'min_max_genes': [325, None], 'min_max_cells': [3, None], 'max_mt': 5, 'min_max_counts': [531, ... 434 1254.328857 6.075346 7.135153 0.000000 0.000000 0.000000 5.846686 0.466121 1.923765 0.000000 0.000000 0.000000 806.0 434 0.022246 False 0 Excitatory Excitatory 0 Excitatory {'resolution': 0.15, 'min_dist': 0.15, 'n_comps': 50} Excitatory {'col_celltype': 'annotation_by_markers_individual_heterogeneous_collapsed', 'flavor': 'scanvi',... 0 0.05 40 1 Neuron 0,0 0.07 0,0 053 Sst Gaba Heterogeneous NaN Inhibitory Heterogeneous
TTTGTTGTCTTGCAGA-1_SRR23052429 SRR23052429 15125 Control {'min_max_genes': [325, None], 'min_max_cells': [3, None], 'max_mt': 5, 'min_max_counts': [531, ... 384 1210.457520 5.953243 7.099579 3.599698 0.297383 1.525991 21.200792 1.751469 3.100128 0.000000 0.000000 0.000000 562.0 384 0.129032 False 1 Microglial Microglial 1 Microglial {'resolution': 0.15, 'min_dist': 0.15, 'n_comps': 50} Microglial {'col_celltype': 'annotation_by_markers_individual_heterogeneous_collapsed', 'flavor': 'scanvi',... 3 0.05 40 1 Microglial 3 0.07 Microglial 335 BAM NN 335 BAM NN 0.014396 Macrophage Macrophage

31446 rows × 42 columns

Get Marker Gene Sets¶

From Google Drive, except senmayo derived from file downloaded from https://www.gsea-msigdb.org/gsea/msigdb/human/geneset/SAUL_SEN_MAYO.html then created using:

from pybiomart import Server

senmayo = pd.read_csv("resources/SAUL_SEN_MAYO.v2025.1.Hs.tsv",
                      sep="\t", header=0)
senmayo = senmayo[senmayo.STANDARD_NAME == "GENE_SYMBOLS"]
senmayo = pd.Series({"Senmayo": senmayo.iloc[0, 1].split(
    ",")}, name="symbol").rename_axis("Gene_Set").explode().str.strip(
        ).replace("", np.nan).dropna().to_frame()
server = Server(host="http://www.ensembl.org")
mart = server.marts["ENSEMBL_MART_ENSEMBL"] # Access the Ensembl mart
human_dataset = mart.datasets["hsapiens_gene_ensembl"]
orthologs = human_dataset.query(attributes=[
    "external_gene_name", "mmusculus_homolog_associated_gene_name"])
orthologs = orthologs.dropna().set_index(orthologs.columns[0])
orthologs = orthologs.loc[orthologs.index.intersection(
    senmayo.symbol.to_list())].iloc[:, 0]
print(f"{orthologs.shape[0]} orthologs found out of"
      f" {len(senmayo.symbol.unique())} senmayo genes")
senmayo = senmayo.assign(symbol=senmayo.replace({"symbol": dict(zip(
    orthologs.index, orthologs.values))}))
senmayo.to_csv("gene_sets/senmayo.csv")

(Also could use scflow.tl.convert_gene_species(senmayo.symbol.to_list()))

Certain gene sets created from Google Drive ADBR AWG > Projects > White Matter > Gene Sets files (with the suffix = "_adjusted") were modified for consistency, e.g.,

pd.read_csv("gene_sets/_iron_genes_gmt_out.csv", index_col=[
    0, 1]).rename_axis(["row_id", "pathway"]).stack().to_frame(
        "symbol").reset_index(-1, drop=True).reset_index().to_csv(
            "gene_sets/_iron_genes_gmt_out_adjusted.csv")
In [14]:
%matplotlib inline

mks = [pd.read_csv(os.path.join("gene_sets", i)).dropna(
    how="all", axis=1).assign(Source_File=i) for i in os.listdir("gene_sets")]
mks = [x.assign(Gene_Set=x["Source_File"].iloc[0].split("_2025")[0]) if (
    "pathway" in x) else x for x in mks]
mks = pd.concat(mks).drop("Unnamed: 0", axis=1).drop("row_id", axis=1)
mks = mks[mks.symbol.isin(self.rna.var_names)]
mks = mks[["Gene_Set", "symbol"]].set_index("Gene_Set").groupby(
    "Gene_Set").apply(lambda x: x["symbol"].to_list())
marker_genes_dict = dict(mks)
marker_gene_sets = mks.copy()
print(marker_gene_sets)
Gene_Set
GOBP_CELLULAR_RESPONSE_TO_IRON_ION                                                                                                                                                                                                       [B2m, Bmp6, Gpld1, Hfe, Ireb2, Tfap2a, Tfr2, Tfrc, Trf]
GOBP_CENTRAL_NERVOUS_SYSTEM_MYELIN_FORMATION                                                                                                                                                                                                [Abca2, Ckap5, Cntn1, Ercc2, Mag, Mios, Tenm4, Tlr2]
GOBP_INTRACELLULAR_IRON_ION_HOMEOSTASIS                                                                                                                                                      [Abcb7, Aco1, Alas2, Atp13a2, Atp6ap1, Atp6v0a2, Atp6v0d1, Atp6v1a, Atp6v1g1, B2m, Bdh2, Bmp6, B...
GOBP_IRON_COORDINATION_ENTITY_TRANSPORT                                                                                                                                                                           [Abcb6, Abcb7, Abcc5, Flvcr1, Flvcr2, Hpx, Pgrmc2, Slc22a17, Slc46a1, Slc48a1]
GOBP_IRON_ION_IMPORT_ACROSS_PLASMA_MEMBRANE                                                                                                                                                                                                                              [Iscu, Slc39a8, Steap2]
GOBP_IRON_ION_TRANSMEMBRANE_TRANSPORT                                                                                                                                                        [Abcb6, Abcb7, Abcc5, Atp7a, Fxn, Hamp, Hamp2, Hif1a, Iscu, Nos1, Scara5, Slc11a1, Slc11a2, Slc2...
GOBP_IRON_ION_TRANSPORT                                                                                                                                                                      [Abcb6, Abcb7, Abcc5, Arhgap1, Atp7a, B2m, Cltc, Cp, Dnm2, Flvcr1, Flvcr2, Fth1, Fxn, Hamp, Hamp...
GOBP_MULTICELLULAR_ORGANISMAL_LEVEL_IRON_ION_HOMEOSTASIS                                                                                                                                     [Ank1, B2m, Bmp6, Btbd9, Cybrd1, Eif2ak1, Epas1, Fbxl5, Fech, Hamp, Hamp2, Hfe, Hmox1, Htt, Hyal...
GOBP_MYELIN_ASSEMBLY                                                                                                                                                                         [Abca2, Cd9, Ckap5, Cntn1, Cntnap1, Dicer1, Epb41l3, Ercc2, Fig4, Gnpat, Gpc1, Ilk, Itgb4, Mag, ...
GOBP_MYELIN_MAINTENANCE                                                                                                                                                                      [Abcd1, Abcd2, Akt1, Akt2, Clu, Cxcr4, Degs1, Epb41l3, Fa2h, Myrf, Ndrg1, Pals1, Plec, Prx, Pten...
GOBP_NEGATIVE_REGULATION_OF_IRON_ION_TRANSMEMBRANE_TRANSPORT                                                                                                                                                                                                    [Atp7a, Hamp, Hamp2, Iscu, Nos1]
GOBP_NEGATIVE_REGULATION_OF_IRON_ION_TRANSPORT                                                                                                                                                                                          [Atp7a, Hamp, Hamp2, Hsd3b2, Hsd3b3, Hsd3b6, Iscu, Nos1]
GOBP_REGULATION_OF_IRON_ION_TRANSMEMBRANE_TRANSPORT                                                                                                                                                                                                             [Atp7a, Hamp, Hamp2, Iscu, Nos1]
GOBP_REGULATION_OF_IRON_ION_TRANSPORT                                                                                                                                                                                    [Atp7a, B2m, Hamp, Hamp2, Hfe, Hsd3b2, Hsd3b3, Hsd3b6, Iscu, Nos1, Trf]
GOBP_REGULATION_OF_MYELINATION                                                                                                                                                               [Akt1, Cdh2, Cdk18, Cst7, Ctnnb1, Ctsc, Cyfip1, Dag1, Dicer1, Dlg1, Egr2, Eif2ak3, Fig4, Hes5, H...
GOBP_RESPONSE_TO_IRON_ION                                                                                                                                                                    [Abat, Aco1, B2m, Bcl2, Bmp6, Casp6, Cybrd1, Fxn, Gpld1, Hamp, Hamp2, Hfe, Ireb2, Lct, Snca, Tfa...
GOBP_SEQUESTERING_OF_IRON_ION                                                                                                                                                                                                                                          [Bdh2, Fth1, Ftl1, Naglu]
GOBP_SPHINGOMYELIN_BIOSYNTHETIC_PROCESS                                                                                                                                                                  [Abca8a, Abca8b, Ormdl1, Ormdl3, Osbp, Pemt, Samd8, Sgms1, Sgms2, Sptlc1, Sptlc2, Vapa]
GOBP_SPHINGOMYELIN_CATABOLIC_PROCESS                                                                                                                                                                                                [Prkcd, Smpd1, Smpd2, Smpd3, Smpd4, Smpd5, Smpdl3a, Smpdl3b]
GOBP_SPHINGOMYELIN_METABOLIC_PROCESS                                                                                                                                                         [Abca2, Abca8a, Abca8b, Ormdl1, Ormdl3, Osbp, Pemt, Prkcd, Samd8, Sgms1, Sgms2, Smpd1, Smpd2, Sm...
GOMF_FERRIC_IRON_BINDING                                                                                                                                                                                                                                  [Acp5, Fth1, Ftl1, Fxn, Rrm2, Th, Trf]
GOMF_FERROUS_IRON_BINDING                                                                                                                                                                    [Acp5, Alkbh1, Alkbh2, Alkbh3, Cdo1, Dnajc24, Egln1, Egln2, Egln3, Fth1, Ftl1, Fto, Fxn, Haao, H...
GOMF_FERROUS_IRON_TRANSMEMBRANE_TRANSPORTER_ACTIVITY                                                                                                                                                                                     [Mmgt1, Slc11a2, Slc25a28, Slc25a37, Slc39a14, Slc40a1]
GOMF_IRON_ION_BINDING                                                                                                                                                                        [Abce1, Aco2, Acp5, Ado, Agmo, Alkbh1, Alkbh2, Alkbh3, Alkbh8, Alox12, Alox12b, Alox5, Alox8, Al...
GOMF_IRON_ION_TRANSMEMBRANE_TRANSPORTER_ACTIVITY                                                                                                                                                                          [Mmgt1, Slc11a1, Slc11a2, Slc25a28, Slc25a37, Slc39a14, Slc40a1, Tfrc]
GOMF_OXIDOREDUCTASE_ACTIVITY_ACTING_ON_PAIRED_DONORS_WITH_INCORPORATION_OR_REDUCTION_OF_MOLECULAR_OXYGEN_REDUCED_IRON_SULFUR_PROTEIN_AS_ONE_DONOR_AND_INCORPORATION_OF_ONE_ATOM_OF_OXYGEN                               [Ahr, Cyp11a1, Cyp2u1, Cyp4a12b, Cyp4f14, Cyp4f15, Cyp4f18, Fdx1, Hmox1]
GOMF_SPHINGOMYELIN_PHOSPHODIESTERASE_ACTIVITY                                                                                                                                                                                              [Smpd1, Smpd2, Smpd3, Smpd4, Smpd5, Smpdl3a, Smpdl3b]
GOMF_STRUCTURAL_CONSTITUENT_OF_MYELIN_SHEATH                                                                                                                                                                             [Cmtm8, Gpm6b, Mal, Mal2, Mall, Marveld1, Mbp, Mobp, Ncmap, Pllp, Plp1]
REACTOME_IRON_UPTAKE_AND_TRANSPORT                                                                                                                                                           [Aco1, Atp6ap1, Atp6v0a1, Atp6v0a2, Atp6v0a4, Atp6v0b, Atp6v0c, Atp6v0d1, Atp6v0e, Atp6v0e2, Atp...
REACTOME_MITOCHONDRIAL_IRON_SULFUR_CLUSTER_BIOGENESIS                                                                                                                                                                      [Fdx1, Fdx2, Fdxr, Fxn, Glrx5, Hscb, Isca1, Isca2, Iscu, Lyrm4, Nfs1]
Senmayo                                                                                                                                                                                      [Acvr1b, Ang, Angpt1, Angptl4, Areg, Axl, Bex3, Bmp2, Bmp6, C3, Ccl2, Ccl24, Ccl3, Ccl4, Ccl5, C...
WP_IRON_HOMEOSTASIS                                                                                                                                                                                             [Fth1, Ftl1, Hamp, Hamp2, Hfe, Il1a, Il6, Il6ra, Ireb2, Slc40a1, Tfr2, Tnf, Trf]
dtype: object

Score Senescence¶

Run Scoring¶

If you want just to find the senescence-related genes, run:

tissue = "Brain"  # or whatever you want here
celltype = None  # or whatever you want here
genes_senepy, hubs, figs = find_senescence_genes(
    self.rna, species=species, tissue=tissue, celltype=celltype,
    overlap_threshold=0, literature_sources=None,
    sengpt_sources=True, plot=True, col_celltype=col_celltype
)  # find tissue- and/or cell type-specific genes

To see available hubs:

hubs = senepy.load_hubs(species=species)
hubs.metadata.set_index(["tissue", "cell"]).sort_index()

Other examples of arguments you could use:

# tissue = ["Brain", "Myeloid"]
# tissue = None

# celltype = "GABA interneuron"  # only human I think
# celltype = ["microglia", "t cell", "monocyte"]
# celltype = "microglia"
# celltype = "microglial cell"`
In [3]:
sc.tl.score_genes(self.rna, marker_gene_sets.loc["Senmayo"],
                  ctrl_as_ref=True, ctrl_size=50, gene_pool=None,
                  n_bins=25, score_name="score_senmayo", random_state=0,
                  copy=False, layer="log1p", use_raw=False)

Label SnCs¶

Define Snc Threshold & Label Cells¶

Based on percentile threshold derived from control group

In [4]:
# Determine Threshold
perc_s, perc = str(100 - percentile) + "%", 1 - (percentile / 100)
p_h = 3
perc_s_h, perc_h = str(100 - p_h) + "%", 1 - (p_h / 100)
print("Percentile for Threshold:", perc_s)
for u in sen_metrics:
    self.rna.obs = self.rna.obs.join(self.rna.obs[self.rna.obs[
        col_batch] == keys[col_batch]["key_control"]].groupby(
            col_celltype).apply(lambda x: x[f"score_{u}"].describe(
                percentiles=[perc])[perc_s], include_groups=False).to_frame(
                    f"Senescence_Threshold_{u}"), on=col_celltype).loc[
                        self.rna.obs.index]
    self.rna.obs = self.rna.obs.join(self.rna.obs[self.rna.obs[
        col_batch] == keys[col_batch]["key_control"]].groupby(
            col_celltype).apply(lambda x: x[f"score_{u}"].describe(
                percentiles=[perc_h])[perc_s_h],
                                include_groups=False).to_frame(
                                    f"Senescence_Threshold_{u}_{p_h}"),
                                on=col_celltype).loc[self.rna.obs.index]

# Binary CLassification
for x in sen_metrics:
    self.rna.obs.loc[:, f"Senescent_Cell_{x}"] = (self.rna.obs[
        f"score_{x}"] >= self.rna.obs[f"Senescence_Threshold_{x}"])
    self.rna.obs.loc[:, f"Senescent_Cell_{x}_{p_h}"] = (self.rna.obs[
        f"score_{x}"] >= self.rna.obs[f"Senescence_Threshold_{x}_{p_h}"])

# String Labels (for Plotting/Categorical Analysis)
for x in sen_metrics:
    self.rna.obs.loc[:, f"Senescent_Cell_Label_{x}"] = self.rna.obs[
        f"Senescent_Cell_{x}"].astype(bool).astype(str).replace({
            "True": "Senescent", "False": "Non-Senescent"})
    self.rna.obs.loc[:, f"Senescent_Cell_Label_hierarchy_{x}"] = self.rna.obs[
        f"Senescent_Cell_{x}"].astype(bool).astype(str).replace({
            "True": "Senescent", "False": "Non-Senescent"})
    self.rna.obs.loc[:, f"Senescent_Cell_Label_{x}_{p_h}"] = self.rna.obs[
        f"Senescent_Cell_{x}_{p_h}"].astype(bool).astype(str).replace({
            "True": "Senescent", "False": "Non-Senescent"})
    self.rna.obs.loc[:, f"Senescent_Cell_Label_by_Type_{x}"] = self.rna.obs[
        f"Senescent_Cell_Label_{x}"].replace({
            "Senescent": "SnC ", "Non-Senescent": ""}) + self.rna.obs[
                col_celltype].astype(str)
    # self.rna.obs.loc[:, f"SnC_hierarchy_{x}"] = self.rna.obs[
    #     f"Senescent_Cell_Label_{x}"].replace({
    #         "Senescent": "SnC ", "Non-Senescent": ""}) + self.rna.obs[
    #             col_celltype + "_hierarchy"].astype(str)

# Descriptives
for x in sen_metrics:
    print(x, round(self.rna.obs[[
        f"Senescent_Cell_Label_{x}", col_celltype]].value_counts(
            normalize=True).sort_index() * 100, 1).unstack(0))

# Choose Metrics for Main Analysis
colssen = ["Senescent_Cell_Label", "Senescent_Cell", "SnC_hierarchy",
           "Senescence_Threshold", "Senescent_Cell_Label_by_Type"]
colssen = [i for i in colssen if f"{i}_{use_metric}" in self.rna.obs]
for x in colssen:
    self.rna.obs.loc[:, x] = self.rna.obs[f"{x}_{use_metric}"]
self.rna.obs.loc[:, "senscore"] = self.rna.obs[f"score_{use_metric}"]
self.rna.obs.loc[
    :, f"Senescent_Cell_Label_by_Type_{use_metric}_{p_h}"] = self.rna.obs[
        f"Senescent_Cell_Label_{use_metric}_{p_h}"].replace({
            "Non-Senescent": "", "Senescent": "SnC "}).astype(
                str) + self.rna.obs[
                    col_celltype].astype(str)  # lower threshold SnC by type
genes = marker_gene_sets.loc["Senmayo"] if (
    use_metric == "senmayo") else genes_senepy  # main senescence gene list

# Avoid Nesting Duplication Issues
# self.rna.obs.loc[:, "SnC_hierarchy"] = self.rna.obs[
#     "SnC_hierarchy"].replace({
#         "Neuron": "Neurons", "SnC Neuron": "SnC Neurons"})
Percentile for Threshold: 99%
senmayo Senescent_Cell_Label_senmayo  Non-Senescent  Senescent
annotation_by_overlap                                 
Neuron                                 53.4        0.5
Oligodendrocyte                        14.4        0.2
Astrocyte                               8.6        0.0
Microglial                              7.2        0.1
OPC                                     5.3        0.0
Endothelial                            10.1        0.1

Label Batch/Cell-Specific Senescence Percentiles¶

In [5]:
# for x in ["Senescence_Label", "Senescence_CellType"]:
#     if x in self.rna.obs:
#         self.rna.obs = self.rna.obs.drop(x, axis=1)

# # %ile Thresholds (Overall)
# thresh = self.rna.obs["score_senepy"].describe(
#     percentiles=[0.90, 0.95, 0.99])
# thres_ct =  self.rna.obs[["score_senepy", col_celltype]].groupby(
#     col_celltype).describe(percentiles=[0.90, 0.95, 0.99])["score_senepy"]

# sen = self.rna.obs["score_senepy"].apply(
#     lambda x: "Top 1%" if x >= float(thresh.loc["99%"]) else "Top 5%" if (
#         x >= float(thresh.loc["95%"])) else "Top 10%" if x >= float(
#             thresh.loc["90%"]) else "Bottom 90%").to_frame(
#                 "Senescence_Label").loc[self.rna.obs.index]
# self.rna.obs = self.rna.obs.join(sen).loc[self.rna.obs.index]

# # %ile Thresholds (by Cell Type)
# sct = self.rna.obs.groupby(
#     col_celltype).apply(lambda g: g["score_senepy"].apply(
#         lambda x: f"Top 1% {g.name}" if x >= float(thres_ct.loc[g.name][
#             "99%"]) else f"Top 5% {g.name}" if (x >= float(thres_ct.loc[
#                 g.name]["95%"])) else f"Top 10% {g.name}" if x >= float(
#                     thres_ct.loc[g.name]["90%"]) else g.name),
#                         include_groups=False)

# sct = sct.to_frame("Senescence_CellType").reset_index(0, drop=True)
# sct = sct.loc[self.rna.obs.index]
# self.rna.obs = self.rna.obs.join(sct).loc[self.rna.obs.index]

# for x in ["Senescence_Label", "Senescence_CellType"]:
#     self.rna.obs = self.rna.obs.assign(**{
#         x: self.rna.obs[x].astype("category")})

# high_sen_cts = [i for i in self.rna.obs["Senescence_CellType"].unique(
#     ) if " 1% " in i]

Descriptives of SnCs¶

In [6]:
print("Percent Senescent: \n\n", round(self.rna.obs.groupby([
    col_celltype, col_batch]).apply(lambda x: x["Senescent_Cell"].astype(
        int).value_counts(normalize=True), include_groups=False) * 100,
    2).unstack(col_celltype))
sns.catplot(self.rna.obs, y="Senescent_Cell", x=col_celltype,
            hue=col_batch, kind="bar", height=10)
Percent Senescent: 

 Senescent_Cell             0                                                              1                                                       
annotation_by_overlap Neuron Oligodendrocyte Astrocyte Microglial    OPC Endothelial Neuron Oligodendrocyte Astrocyte Microglial   OPC Endothelial
Condition                                                                                                                                         
Control                99.00           98.99     99.00      98.98  99.00       98.98   1.00            1.01      1.00       1.02  1.00        1.02
Irradiated             99.13           98.69     99.77      99.23  99.27       98.48   0.87            1.31      0.23       0.77  0.73        1.52
Out[6]:
<seaborn.axisgrid.FacetGrid at 0x70af43fd1d30>

SnC DEGs¶

Overall¶

In [7]:
p_threshold = 1e-10
lfc_threshold = 1
self.find_markers(col_celltype="Senescent_Cell_Label_by_Type")
df_snc_markers = {}
df_snc_markers["All"] = self.get_markers_df(
    n_genes=50, col_celltype="Senescent_Cell_Label_by_Type",
    log2fc_threshold=1, p_threshold=1e-10)
# print(df_snc_markers["All"].loc[pd.unique([
#     i[0] for i in df_snc_markers["All"].index.values if (
#         "SnC" in i[0])])].groupby("Senescent_Cell_Label_by_Type").apply(
#             lambda x: x.head(3)))
for x in self.rna.obs[col_celltype].unique():
    df_snc_markers[x] = self.find_markers(
        col_celltype="Senescent_Cell_Label_by_Type",
        reference=x, groups=[x, f"SnC {x}"], rankby_abs=True,
        inplace=False).reset_index(0, drop=True).assign(**{
            col_celltype: f"SnC {x}"}).reset_index().set_index([
                col_celltype, "names"])
df_snc_markers = pd.concat(df_snc_markers, names=["Comparison"])
df_snc_markers = df_snc_markers.rename_axis([
    "Comparison", col_celltype, "names"]).rename({
        "logfoldchanges": "log_fc"}, axis=1).assign(
            log_fc_abs=df_snc_markers["logfoldchanges"].abs())
df_snc_markers_top = df_snc_markers[df_snc_markers.pvals_adj < p_threshold]
df_snc_markers_top = df_snc_markers_top[
    df_snc_markers.log_fc_abs >= lfc_threshold]
df_snc_markers_top = df_snc_markers_top.groupby([
    "Comparison", col_celltype]).apply(
        lambda x: x.assign(scores_abs=x.scores.abs()).sort_values(
            "scores_abs", ascending=False).head(20),
        include_groups=False).reset_index([0, 1], drop=True)
... storing 'Senescent_Cell_Label_senmayo' as categorical
... storing 'Senescent_Cell_Label_hierarchy_senmayo' as categorical
... storing 'Senescent_Cell_Label_senmayo_3' as categorical
... storing 'Senescent_Cell_Label_by_Type_senmayo' as categorical
... storing 'Senescent_Cell_Label' as categorical
... storing 'Senescent_Cell_Label_by_Type' as categorical
... storing 'Senescent_Cell_Label_by_Type_senmayo_3' as categorical
... storing 'Senescent_Cell_Label_hierarchy_senmayo' as categorical
... storing 'Senescent_Cell_Label_senmayo_3' as categorical
... storing 'Senescent_Cell_Label_by_Type_senmayo' as categorical
... storing 'Senescent_Cell_Label' as categorical
... storing 'Senescent_Cell_Label_by_Type' as categorical
... storing 'Senescent_Cell_Label_by_Type_senmayo_3' as categorical

By Group¶

In [8]:
res_rank_genes, p_threshold = {}, 1e-10
for x in self.rna.obs[col_batch].unique():
    res_rank_genes[x] = {}
    for c in self.rna.obs[self.rna.obs[col_batch] == x][
            col_celltype].unique():
        s_iter = (self.rna.obs[col_batch] == x) & (self.rna.obs[
            "Senescent_Cell_Label_by_Type"].isin([c, f"SnC {c}"]))
        tmp = sc.tl.rank_genes_groups(
            self.rna[s_iter], "Senescent_Cell_Label_by_Type", rankby_abs=True,
            layer="log1p", groups=[c, f"SnC {c}"], reference=c, copy=True)
        res_rank_genes[x][c] = sc.get.rank_genes_groups_df(
            tmp, f"SnC {c}", pval_cutoff=p_threshold)
    tmp = sc.tl.rank_genes_groups(
            self.rna[self.rna.obs[col_batch] == x],
            "Senescent_Cell_Label", rankby_abs=True,
            layer="log1p", reference="Non-Senescent", copy=True)
    res_rank_genes[x]["Overall"] = sc.get.rank_genes_groups_df(
            tmp, f"Senescent", pval_cutoff=p_threshold)
    res_rank_genes[x] = pd.concat(res_rank_genes[x], names=[col_celltype])
res_rank_genes = pd.concat(res_rank_genes, names=[col_batch])
res_rank_genes = res_rank_genes.assign(
    logfoldchanges_abs=res_rank_genes.logfoldchanges.abs())
res_rank_genes_top = res_rank_genes.reset_index().groupby([
    col_batch, col_celltype]).apply(
        lambda x: x.sort_values("logfoldchanges_abs").iloc[:20],
        include_groups=False).reset_index(2, drop=True).set_index(
            "names", append=True).rename_axis([
                col_batch, col_celltype, "variable"])
res_rank_genes_top
Out[8]:
level_2 scores logfoldchanges pvals pvals_adj logfoldchanges_abs
Condition annotation_by_overlap variable
Control Astrocyte Gask1a 2280 -6.899581 -26.121424 9.310845e-12 9.491674e-11 26.121424
Impa1 2205 -6.990173 -26.129885 5.050043e-12 5.323148e-11 26.129885
Gm4631 2289 -6.891666 -26.156315 9.818823e-12 9.970179e-11 26.156315
Cox20 2281 -6.899323 -26.160561 9.327006e-12 9.503982e-11 26.160561
Prr3 2233 -6.959009 -26.185480 6.237844e-12 6.492774e-11 26.185480
Nacc1 2229 -6.962988 -26.185501 6.072125e-12 6.331620e-11 26.185501
B4gat1 2209 -6.986256 -26.186867 5.186150e-12 5.456722e-11 26.186867
Ankrd13b 2207 -6.987902 -26.208654 5.128528e-12 5.400981e-11 26.208654
Acad11 1991 -7.287731 -26.212959 6.448995e-13 7.528036e-12 26.212959
Mxd1 2286 -6.894303 -26.223953 9.646633e-12 9.808184e-11 26.223953
Puf60 2272 -6.909818 -26.227179 8.691965e-12 8.891961e-11 26.227179
Nelfa 2217 -6.976876 -26.233416 5.526904e-12 5.794278e-11 26.233416
Smarcd2 2179 -7.029249 -26.234095 3.870448e-12 4.128419e-11 26.234095
Fastkd1 2144 -7.076927 -26.236900 2.792794e-12 3.027545e-11 26.236900
C1qb 2276 -6.905093 -26.239056 8.972439e-12 9.162764e-11 26.239056
Metrn 2188 -7.016893 -26.241781 4.210715e-12 4.472898e-11 26.241781
Srfbp1 2095 -7.155615 -26.247286 1.623019e-12 1.800575e-11 26.247286
Zscan22 2135 -7.090904 -26.250580 2.537091e-12 2.761938e-11 26.250580
Tmem62 2273 -6.908015 -26.250883 8.797921e-12 8.996397e-11 26.250883
Rnf181 2161 -7.058301 -26.252621 3.173249e-12 3.412931e-11 26.252621
Endothelial Zfp783 1602 -6.949718 -26.358297 6.713847e-12 9.739058e-11 26.358297
Itpk1 1588 -6.977891 -26.359802 5.549072e-12 8.120363e-11 26.359802
Gm9801 1423 -7.248925 -26.388727 8.577229e-13 1.400065e-11 26.388727
Ercc4 1597 -6.962916 -26.418657 6.141034e-12 8.936011e-11 26.418657
Tmem63a 1605 -6.948704 -26.419216 6.760004e-12 9.787695e-11 26.419216
Gga2 1595 -6.964891 -26.423132 6.059564e-12 8.828512e-11 26.423132
Mphosph10 1554 -7.034715 -26.430445 3.770793e-12 5.638730e-11 26.430445
Nmrk1 1590 -6.973176 -26.448242 5.729182e-12 8.373392e-11 26.448242
Rpgrip1l 1504 -7.100945 -26.462038 2.395427e-12 3.701054e-11 26.462038
Mios 1574 -7.004398 -26.466330 4.635521e-12 6.843795e-11 26.466330
Gm5089-1 1521 -7.071217 -26.473644 2.937854e-12 4.488430e-11 26.473644
Gm40841 1592 -6.968529 -26.475462 5.912255e-12 8.630111e-11 26.475462
Abtb2 1561 -7.015383 -26.479740 4.301790e-12 6.403938e-11 26.479740
2010315B03Rik 1520 -7.071331 -26.480158 2.935554e-12 4.487866e-11 26.480158
Zfp810 1505 -7.096443 -26.484945 2.470749e-12 3.814895e-11 26.484945
4930557K07Rik 1568 -7.010933 -26.492561 4.434019e-12 6.571335e-11 26.492561
Zscan21 1532 -7.053749 -26.498459 3.311052e-12 5.022303e-11 26.498459
Bicd2 1578 -6.999868 -26.500721 4.780432e-12 7.039860e-11 26.500721
Klhl28 1437 -7.223825 -26.503307 1.022263e-12 1.653038e-11 26.503307
Cpne2 1570 -7.008232 -26.508034 4.516236e-12 6.684662e-11 26.508034
Microglial Kcna6 2260 -6.986748 -26.204020 5.212861e-12 5.361108e-11 26.204020
1810062O18Rik 2300 -6.939326 -26.208084 7.184250e-12 7.260120e-11 26.208084
Klhl4 2246 -7.001433 -26.244047 4.718151e-12 4.882562e-11 26.244047
Rhou 2328 -6.903688 -26.250216 9.131184e-12 9.116678e-11 26.250216
Galnt6 2224 -7.036579 -26.269043 3.713725e-12 3.881135e-11 26.269043
Dennd11 2088 -7.226976 -26.280603 9.972177e-13 1.110019e-11 26.280603
Ddx27 2325 -6.904808 -26.285957 9.062797e-12 9.060069e-11 26.285957
Fbxo21 2104 -7.205569 -26.304873 1.157843e-12 1.279017e-11 26.304873
Fads1 2113 -7.195772 -26.306011 1.239584e-12 1.363484e-11 26.306011
Timp3 2333 -6.897698 -26.306894 9.505706e-12 9.470274e-11 26.306894
Plxnb3 1880 -7.528371 -26.308655 1.169682e-13 1.445966e-12 26.308655
Rad51d 2211 -7.053523 -26.308823 3.307721e-12 3.477144e-11 26.308823
Cpeb1 2301 -6.935561 -26.311361 7.368957e-12 7.443543e-11 26.311361
Fsd1l 2081 -7.232708 -26.312981 9.580622e-13 1.069678e-11 26.312981
Fkbp4 2323 -6.906555 -26.317469 8.957033e-12 8.962044e-11 26.317469
Scyl2 2257 -6.989792 -26.317867 5.106294e-12 5.258488e-11 26.317867
Stk38l 2307 -6.928331 -26.319429 7.736780e-12 7.794772e-11 26.319429
Adam19 2201 -7.070250 -26.322065 2.949762e-12 3.114933e-11 26.322065
Zfp932 2330 -6.901375 -26.324280 9.274037e-12 9.251359e-11 26.324280
Snupn 2298 -6.940219 -26.326311 7.141062e-12 7.222754e-11 26.326311
Neuron Nrg1 3173 8.050385 2.319905 5.969480e-12 3.572930e-11 2.319905
Lingo2 3247 -7.922422 -2.549603 9.939715e-12 5.900643e-11 2.549603
Pkn2 3347 -7.782115 -2.937992 1.404550e-11 8.272546e-11 2.937992
Eml4 3194 -8.012017 -3.025077 4.886238e-12 2.941991e-11 3.025077
1700109K24Rik 3434 -7.638855 -3.263194 1.632864e-11 9.580873e-11 3.263194
Cbx1 3344 -7.785600 -3.300246 6.842422e-12 4.082803e-11 3.300246
Eya3 3248 -7.918816 -3.347942 6.071926e-12 3.633312e-11 3.347942
Ttll11 2322 -9.975977 -3.367642 4.280561e-16 3.195374e-15 3.367642
Map2k1 3168 -8.056600 -3.381367 3.005415e-12 1.834250e-11 3.381367
Usp47 2979 -8.436843 -3.484838 5.996641e-13 3.805674e-12 3.484838
Naa35 2756 -8.897054 -3.496942 3.177868e-14 2.149985e-13 3.496942
Crppa 2723 -8.977502 -3.518860 1.763098e-14 1.205449e-13 3.518860
Gpr45 2701 -9.029871 -3.521290 1.536086e-14 1.052715e-13 3.521290
Slc8a3 2917 -8.564902 -3.527269 3.205010e-13 2.063292e-12 3.527269
Cpsf7 2657 -9.167022 -3.543409 9.182847e-15 6.379705e-14 3.543409
Sh3kbp1 2800 -8.816453 -3.557840 8.764333e-14 5.814466e-13 3.557840
Nsmf 2397 -9.754376 -3.635741 3.793067e-16 2.835107e-15 3.635741
Pvt1 2506 -9.495745 -3.652252 2.773640e-15 1.991830e-14 3.652252
Ppip5k1 2374 -9.824734 -3.712110 7.031471e-16 5.188918e-15 3.712110
Efcab14 2235 -10.248778 -3.713273 1.506499e-17 1.201737e-16 3.713273
OPC 6030458C11Rik 3005 -6.909232 -26.472033 1.260549e-11 9.751012e-11 26.472033
Cse1l 2991 -6.918736 -26.612226 1.184731e-11 9.207401e-11 26.612226
Gm36279 2958 -6.949004 -26.637449 9.719124e-12 7.637675e-11 26.637449
Dhps 2937 -6.968986 -26.642302 8.524903e-12 6.747092e-11 26.642302
Zfyve27 2755 -7.187681 -26.645676 1.990234e-12 1.679205e-11 26.645676
Prdm15 2850 -7.070891 -26.651577 4.347695e-12 3.545082e-11 26.651577
Osbpl7 2981 -6.932062 -26.663149 1.085922e-11 8.467791e-11 26.663149
Tada3 2844 -7.074673 -26.668850 4.239748e-12 3.465268e-11 26.668850
Tmem9 2998 -6.913056 -26.676514 1.229489e-11 9.532944e-11 26.676514
Gm10509 2827 -7.089220 -26.688534 3.848565e-12 3.164451e-11 26.688534
Tmem216 2804 -7.118502 -26.699247 3.165615e-12 2.624244e-11 26.699247
Pcnt 2986 -6.925227 -26.708757 1.135548e-11 8.839942e-11 26.708757
Lekr1 2851 -7.070878 -26.719002 4.348073e-12 3.545082e-11 26.719002
Mapkapk5 2938 -6.968518 -26.720018 8.551150e-12 6.765563e-11 26.720018
Tigd2 2832 -7.085433 -26.720942 3.946854e-12 3.239541e-11 26.720942
Zc3h4 2766 -7.177059 -26.727606 2.137736e-12 1.796486e-11 26.727606
Flii 2951 -6.957775 -26.728912 9.175941e-12 7.227918e-11 26.728912
E530011L22Rik 2793 -7.130991 -26.736908 2.911963e-12 2.423474e-11 26.736908
Nsrp1 2864 -7.052602 -26.737486 4.909019e-12 3.984273e-11 26.737486
Ddx31 2900 -7.011927 -26.738138 6.425159e-12 5.150094e-11 26.738138
Oligodendrocyte Ephx1 3477 -6.919549 -24.765638 5.820073e-12 3.890668e-11 24.765638
Zfp362 3465 -6.930821 -24.822063 5.383161e-12 3.611501e-11 24.822063
Gm47071 3542 -6.829268 -24.837658 1.082748e-11 7.106161e-11 24.837658
Zfp973 3528 -6.851582 -24.844479 9.293851e-12 6.123829e-11 24.844479
Gm34102 3506 -6.882592 -24.848976 7.510754e-12 4.979971e-11 24.848976
Msh6 3494 -6.897627 -24.869278 6.771619e-12 4.505306e-11 24.869278
2810405F17Rik 3563 -6.810897 -24.874187 1.227399e-11 8.008057e-11 24.874187
Zfp235 3569 -6.797942 -24.876362 1.340634e-11 8.732148e-11 24.876362
Msantd3 3530 -6.849435 -24.886700 9.431638e-12 6.211098e-11 24.886700
Gm36992 3485 -6.910020 -24.886829 6.216372e-12 4.146566e-11 24.886829
Rfx1 3496 -6.894897 -24.890697 6.900321e-12 4.588309e-11 24.890697
Gm57450 3531 -6.849241 -24.894854 9.444156e-12 6.217581e-11 24.894854
Gm28319 3517 -6.869056 -24.896570 8.243527e-12 5.448742e-11 24.896570
Tchp 3567 -6.802267 -24.899517 1.301737e-11 8.483545e-11 24.899517
Gm7580 3560 -6.813012 -24.908638 1.209832e-11 7.900092e-11 24.908638
1810024B03Rik 3554 -6.820371 -24.912777 1.150587e-11 7.525908e-11 24.912777
Vhl 3580 -6.778639 -24.913134 1.528568e-11 9.925664e-11 24.913134
Mavs 3395 -7.024431 -24.917418 2.803053e-12 1.919299e-11 24.917418
Washc1 3553 -6.820608 -24.918327 1.148722e-11 7.515822e-11 24.918327
Gm38190 3524 -6.858548 -24.922430 8.860271e-12 5.844763e-11 24.922430
Overall Lingo2 2127 -8.076390 -2.025966 2.349061e-13 2.184035e-12 2.025966
Csmd2 2415 -7.515627 -2.039679 5.323630e-12 4.490039e-11 2.039679
Nrg1 2304 7.730591 2.066571 1.815066e-12 1.583111e-11 2.066571
Cpsf7 2441 -7.470273 -2.290125 5.792747e-12 4.869803e-11 2.290125
Pik3c2a 2386 -7.570843 -2.357622 3.717092e-12 3.169547e-11 2.357622
Gramd1a 2354 -7.638606 -2.831724 1.705469e-12 1.490875e-11 2.831724
Rnpepl1 1991 -8.393601 -2.928216 1.505719e-14 1.513072e-13 2.928216
Trim11 2554 -7.249123 -3.166181 1.209304e-11 9.964545e-11 3.166181
Dhx16 2322 -7.704764 -3.244049 9.716198e-13 8.662989e-12 3.244049
C030017B01Rik 2324 -7.693622 -3.245649 1.210974e-12 1.070269e-11 3.245649
Zscan21 2300 -7.733488 -3.250508 8.087464e-13 7.246928e-12 3.250508
Zfp949 2272 -7.794486 -3.266035 7.974974e-13 7.148885e-12 3.266035
2300009A05Rik 2230 -7.884248 -3.288992 2.478510e-13 2.298875e-12 3.288992
Dynlt3 2215 -7.913293 -3.304000 1.864495e-13 1.748958e-12 3.304000
Supt6 1361 -10.216332 -3.324451 3.370864e-19 4.504753e-18 3.324451
Tmem98 2125 -8.081484 -3.335211 6.440449e-14 6.216678e-13 3.335211
Larp1b 2020 -8.324810 -3.356950 2.364979e-14 2.345112e-13 3.356950
Qrsl1 2022 -8.323662 -3.367474 1.574788e-14 1.581111e-13 3.367474
Hmgxb3 1934 -8.518602 -3.392382 1.099099e-14 1.116042e-13 3.392382
Dus2 1814 -8.802080 -3.430791 1.325676e-15 1.433765e-14 3.430791
Irradiated Astrocyte A630072M18Rik 6378 -6.789264 -25.188158 1.550951e-11 5.653591e-11 25.188158
Mppe1 6487 -6.702825 -25.270821 2.769870e-11 9.927219e-11 25.270821
2810407A14Rik 6461 -6.723152 -25.274426 2.418208e-11 8.701733e-11 25.274426
Gcdh 6409 -6.762178 -25.288214 1.861376e-11 6.752351e-11 25.288214
4933411O13Rik 6349 -6.820421 -25.311249 1.256306e-11 4.600455e-11 25.311249
Tcta 6460 -6.723157 -25.313372 2.418132e-11 8.701733e-11 25.313372
Mphosph6 6452 -6.728378 -25.318380 2.335123e-11 8.414477e-11 25.318380
4930419G24Rik 6390 -6.772641 -25.319515 1.734840e-11 6.312037e-11 25.319515
Gm13110 6484 -6.707195 -25.324516 2.690270e-11 9.646390e-11 25.324516
Mllt1 6199 -6.998587 -25.324635 3.703037e-12 1.388818e-11 25.324635
Dnajc4 6406 -6.764428 -25.326435 1.833430e-11 6.654090e-11 25.326435
Arsg 6387 -6.776132 -25.326986 1.694535e-11 6.168286e-11 25.326986
Zfp3 6403 -6.766725 -25.328766 1.805315e-11 6.555119e-11 25.328766
Zfp446 6313 -6.865264 -25.331081 9.262611e-12 3.411205e-11 25.331081
Eif2b2 6486 -6.706982 -25.333353 2.694104e-11 9.657159e-11 25.333353
Gtf2h4 6366 -6.805056 -25.335930 1.394012e-11 5.091089e-11 25.335930
Mettl13 6424 -6.748413 -25.337679 2.041705e-11 7.389225e-11 25.337679
Dapk3 6318 -6.860577 -25.343401 9.563254e-12 3.519138e-11 25.343401
Card19 6412 -6.757761 -25.344191 1.917474e-11 6.952599e-11 25.344191
Acadvl 6271 -6.912005 -25.345047 6.728656e-12 2.494602e-11 25.345047
Endothelial Sec22a 368 -8.457185 -3.686894 5.586065e-13 1.932928e-11 3.686894
Arhgap42 55 -11.863465 -3.804621 4.519824e-18 3.401277e-16 3.804621
Scarb2 208 -9.539674 -3.898026 1.449806e-15 7.458482e-14 3.898026
Uso1 168 -9.942991 -3.971739 1.442084e-16 8.554278e-15 3.971739
Pag1 147 -10.115646 -4.024225 2.992701e-17 1.982601e-15 4.024225
Igsf8 34 -12.720626 -4.462536 1.130658e-24 2.142181e-22 4.462536
Poglut2 727 -7.060747 -25.280041 2.212096e-12 7.065640e-11 25.280041
Ptges 707 -7.114425 -25.295591 1.514166e-12 4.973008e-11 25.295591
Gm26936 741 -7.023195 -25.314093 2.879358e-12 9.023410e-11 25.314093
Gapdhs 742 -7.017662 -25.323154 2.993089e-12 9.361002e-11 25.323154
Tead3 720 -7.086849 -25.323721 1.840311e-12 5.935194e-11 25.323721
Nek4 747 -7.010980 -25.333645 3.136300e-12 9.749784e-11 25.333645
Rsf1os2 721 -7.071161 -25.340025 2.055674e-12 6.620579e-11 25.340025
Mavs 731 -7.047999 -25.350563 2.419551e-12 7.686042e-11 25.350563
Gm51425 740 -7.026229 -25.357618 2.818812e-12 8.845592e-11 25.357618
Nrde2 715 -7.096401 -25.358782 1.720198e-12 5.586560e-11 25.358782
D2hgdh 711 -7.108931 -25.375664 1.574259e-12 5.141326e-11 25.375664
Med19 735 -7.033466 -25.381289 2.679396e-12 8.465217e-11 25.381289
Nol9 709 -7.111861 -25.382990 1.541917e-12 5.049888e-11 25.382990
AU041133 729 -7.055797 -25.384651 2.290484e-12 7.295978e-11 25.384651
Microglial Unc5b 2644 -6.878332 -25.846020 9.412005e-12 8.274380e-11 25.846020
Folh1 2623 -6.892336 -25.899731 8.559939e-12 7.585528e-11 25.899731
Insc 2388 -7.189724 -25.919909 1.095836e-12 1.066617e-11 25.919909
Ccdc167 2664 -6.850171 -25.928270 1.138487e-11 9.933673e-11 25.928270
Rhou 2629 -6.888390 -25.937660 8.792090e-12 7.773478e-11 25.937660
Mb21d2 2621 -6.894429 -25.963142 8.439308e-12 7.483579e-11 25.963142
Hhip 2466 -7.097471 -25.963591 2.090570e-12 1.970491e-11 25.963591
Pogk 2639 -6.880940 -25.964931 9.247229e-12 8.144917e-11 25.964931
1810062O18Rik 2486 -7.073106 -25.969307 2.476362e-12 2.315353e-11 25.969307
Pgls 2646 -6.875598 -25.975105 9.587813e-12 8.422570e-11 25.975105
Prmt1 2662 -6.851419 -25.976753 1.128939e-11 9.857760e-11 25.976753
Ptprf 2583 -6.946054 -25.986862 5.938811e-12 5.344240e-11 25.986862
4930511M06Rik 2518 -7.024551 -25.990120 3.465115e-12 3.198663e-11 25.990120
Nudt9 2649 -6.871415 -25.997547 9.863059e-12 8.654556e-11 25.997547
Blvra 2661 -6.852067 -25.999416 1.124022e-11 9.818516e-11 25.999416
Gdpd5 2470 -7.091338 -26.000399 2.181718e-12 2.053075e-11 26.000399
Acad12 2642 -6.879439 -26.004448 9.341737e-12 8.218820e-11 26.004448
Slc22a5 2628 -6.890040 -26.004778 8.694288e-12 7.689930e-11 26.004778
1810030O07Rik 2605 -6.915238 -26.005844 7.326813e-12 6.537620e-11 26.005844
Aga 2633 -6.885250 -26.009266 8.981189e-12 7.928610e-11 26.009266
Neuron Fam135a 2832 -8.632769 -3.078554 3.122162e-13 2.079623e-12 3.078554
Trpc4 3232 -7.804288 -3.324122 1.102129e-11 6.686095e-11 3.324122
Glud1 3207 -7.866503 -3.329096 8.927300e-12 5.447035e-11 3.329096
Rcor1 3143 -7.973571 -3.368381 6.099790e-12 3.759301e-11 3.368381
Ddx42 3054 -8.156442 -3.384334 2.391523e-12 1.515261e-11 3.384334
Nexmif 3047 -8.168753 -3.418451 2.447089e-12 1.549623e-11 3.418451
Gtf2ird1 2680 -8.957244 -3.534790 5.289130e-14 3.650583e-13 3.534790
Ryk 2626 -9.085474 -3.541696 2.675874e-14 1.867971e-13 3.541696
Clint1 2601 -9.138764 -3.568112 2.349956e-14 1.644899e-13 3.568112
Ggt7 2310 -9.895699 -3.671444 5.379075e-16 4.075583e-15 3.671444
P2ry14 2250 -10.052299 -3.690121 1.892486e-16 1.463938e-15 3.690121
2610035D17Rik 1881 -11.157224 -3.852007 6.488225e-19 5.585735e-18 3.852007
Kdm7a 1652 -11.979156 -3.961059 1.214794e-20 1.124955e-19 3.961059
D030016M11Rik 3815 -6.826263 -22.572346 9.286502e-12 5.660263e-11 22.572346
Msh4 3826 -6.812855 -22.646030 1.018998e-11 6.193090e-11 22.646030
Ppp1r13l 3695 -6.985154 -22.673729 3.050056e-12 1.920470e-11 22.673729
Gm42560 3871 -6.741601 -22.676167 1.664109e-11 9.993677e-11 22.676167
Epo 3715 -6.962013 -22.680660 3.592442e-12 2.249799e-11 22.680660
Gm34081 3725 -6.948550 -22.683453 3.950391e-12 2.467323e-11 22.683453
4930558K02Rik 3866 -6.748776 -22.690807 1.584261e-11 9.526460e-11 22.690807
OPC Hsdl2 5151 -6.765785 -25.648161 2.163573e-11 9.765018e-11 25.648161
Spink10 5062 -6.855650 -25.722908 1.188445e-11 5.458210e-11 25.722908
Alg8 5093 -6.818944 -25.726818 1.519223e-11 6.934920e-11 25.726818
Pak1ip1 4993 -6.925550 -25.729536 7.421841e-12 3.455111e-11 25.729536
Utp4 5106 -6.807382 -25.729616 1.640994e-11 7.471713e-11 25.729616
Pdcd7 5058 -6.860917 -25.732944 1.147192e-11 5.272911e-11 25.732944
Fbxw17 4948 -6.960145 -25.744556 5.870012e-12 2.758040e-11 25.744556
Zbtb8os 5149 -6.766804 -25.747093 2.149008e-11 9.703082e-11 25.747093
Gm11713 5122 -6.788765 -25.748745 1.857471e-11 8.430955e-11 25.748745
Grsf1 5154 -6.764911 -25.765440 2.176143e-11 9.814847e-11 25.765440
Zfp868 5005 -6.916277 -25.765907 7.902052e-12 3.670524e-11 25.765907
ENSMUSG00000121477 4958 -6.949397 -25.775723 6.314469e-12 2.960886e-11 25.775723
Rwdd4a 5110 -6.803767 -25.778816 1.680997e-11 7.647860e-11 25.778816
Zfp956 5127 -6.784667 -25.780180 1.908766e-11 8.655332e-11 25.780180
Zfp873 5087 -6.825288 -25.782236 1.456219e-11 6.655159e-11 25.782236
Fbxo36 5031 -6.891016 -25.782383 9.370344e-12 4.330060e-11 25.782383
Tfam 5043 -6.875496 -25.785503 1.040188e-11 4.795300e-11 25.785503
Pomt1 5011 -6.911509 -25.786844 8.160709e-12 3.786133e-11 25.786844
Slc16a11 5126 -6.785153 -25.787155 1.902605e-11 8.629076e-11 25.787155
Cox20 5071 -6.844211 -25.787535 1.283118e-11 5.882559e-11 25.787535
Oligodendrocyte Cox6b2 2499 -6.848058 -24.917793 9.691768e-12 9.014507e-11 24.917793
D330041H03Rik 2498 -6.851861 -24.998604 9.442794e-12 8.786446e-11 24.998604
Fam3a 2426 -6.947983 -25.020468 4.869731e-12 4.665672e-11 25.020468
Dnajc14 2504 -6.839948 -25.029503 1.024444e-11 9.509543e-11 25.029503
Acot11 2509 -6.834937 -25.038433 1.060122e-11 9.821126e-11 25.038433
Gm9856 2470 -6.884237 -25.052404 7.562148e-12 7.116254e-11 25.052404
Dnm3os 2489 -6.863548 -25.061670 8.716271e-12 8.139737e-11 25.061670
Speg 2506 -6.837115 -25.068579 1.044465e-11 9.687651e-11 25.068579
Casp9 2279 -7.188853 -25.075972 8.926310e-13 9.103662e-12 25.075972
Lrrtm2 2350 -7.058453 -25.076599 2.251312e-12 2.226702e-11 25.076599
Glb1l 2502 -6.840386 -25.084822 1.021379e-11 9.488662e-11 25.084822
Stk35 2428 -6.947603 -25.084948 4.882583e-12 4.674134e-11 25.084948
Mrps22 2389 -7.002016 -25.085733 3.343684e-12 3.252578e-11 25.085733
Orai2 2450 -6.913352 -25.087631 6.187919e-12 5.870571e-11 25.087631
Elfn2 2408 -6.978989 -25.088171 3.926004e-12 3.789596e-11 25.088171
Elac2 2431 -6.944227 -25.088694 4.998185e-12 4.778898e-11 25.088694
Armc10 2420 -6.958464 -25.091488 4.528203e-12 4.349207e-11 25.091488
Dnlz 2495 -6.857392 -25.093216 9.091860e-12 8.470073e-11 25.093216
Gm28370 2418 -6.970744 -25.093443 4.157820e-12 3.996767e-11 25.093443
1700123M08Rik 2491 -6.860540 -25.093962 8.897828e-12 8.302617e-11 25.093962
Overall Pitpnm2 2193 -7.505684 -2.061245 3.172325e-12 3.020723e-11 2.061245
Ggt7 2213 -7.458680 -2.371789 3.898433e-12 3.684970e-11 2.371789
Lix1 2252 -7.361102 -2.553793 5.604568e-12 5.235959e-11 2.553793
Stam2 1746 -8.460017 -2.699703 8.745366e-15 9.983113e-14 2.699703
Fbxo31 2171 -7.535775 -2.782398 1.716558e-12 1.667299e-11 2.782398
Trpc4 2052 -7.753718 -2.823491 6.045673e-13 6.049054e-12 2.823491
BC005624 2157 -7.556738 -2.909979 1.726864e-12 1.675908e-11 2.909979
Prmt8 1504 -9.136306 -3.074284 1.279547e-16 1.637496e-15 3.074284
Zfyve27 1741 -8.479522 -3.092191 6.571245e-15 7.542012e-14 3.092191
Pip4k2b 1544 -9.010604 -3.099998 2.200058e-16 2.772788e-15 3.099998
Slc8b1 2331 -7.214657 -3.180256 7.567863e-12 6.997038e-11 3.180256
Gm27032 2216 -7.454336 -3.181952 3.258487e-12 3.100229e-11 3.181952
Gm10785 2201 -7.484264 -3.193166 3.019420e-12 2.879843e-11 3.193166
Gys1 2172 -7.533546 -3.201564 2.156011e-12 2.078512e-11 3.201564
Repin1 2332 -7.209423 -3.203898 6.265153e-12 5.832009e-11 3.203898
Plpp4 2096 -7.667815 -3.234197 8.710664e-13 8.630126e-12 3.234197
Rnf181 2078 -7.692501 -3.238452 5.712596e-13 5.723180e-12 3.238452
Kcnk10 1281 -9.873293 -3.249069 7.476869e-19 1.094145e-17 3.249069
Rims4 2029 -7.814366 -3.251194 3.901264e-13 3.959672e-12 3.251194
Abcb8 1997 -7.874917 -3.259926 2.426751e-13 2.504627e-12 3.259926

Plot¶

Comparison¶

In [15]:
scores = self.rna.obs[[col_batch] + [
    f"score_{x}" for x in sen_metrics]].set_index(
        col_batch, append=True).reset_index()
sns.pairplot(scores, diag_kind="kde", diag_kws=dict(
    cut=0, fill=True, common_norm=True),
             hue=col_batch, palette=palette[col_batch])
Out[15]:
<seaborn.axisgrid.PairGrid at 0x70ac30e80690>
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image

Scores¶

In [ ]:
# UMAP with Senescence Scores
bnds = self.rna.obs["senscore"].describe(percentiles=[0.75, 0.99])
_ = self.plot(kind="umap", color=["senscore", col_celltype], umap=dict(
    palette=None, color_map="Reds", vmin=bnds["75%"], vmax=bnds["99%"]))

# Violin Plot of Senescence Scores
_ = self.plot(kind="violin", genes=["senscore"], common_norm=True,
              col_celltype=col_celltype, rotation=90)
_ = self.plot(kind="violin", genes=["senscore"], common_norm=True,
              by_group=col_celltype, col_wrap=1,
              col_celltype=col_batch, rotation=90)

# KDE
fig_sen_kde = sns.displot(self.rna.obs, hue=col_condition, x="senscore",
                          palette=palette[col_condition], kind="kde",
                          cut=0, common_norm=True, fill=True)

# Overall (All Cell Types)
fig_sen_overall = sns.catplot(self.rna.obs, x=col_condition,
                              hue=col_condition, y="senscore",
                              palette=palette[col_condition],
                              kind="violin")

# By Cell Type
fig_sen = sns.catplot(self.rna.obs, x=col_celltype, y="senscore",
                      palette=palette[col_condition],
                      hue=col_condition, kind="box", height=10, aspect=2)
for a in fig_sen.axes.flatten():
    a.tick_params(axis="x", labelrotation=90)
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image

Burden¶

Group by sample and cell type and get percentage of senescent cells

In [ ]:
 
Out[ ]:
annotation_by_overlap Neuron Oligodendrocyte Astrocyte Microglial OPC Endothelial
Condition
Control 1.00 1.01 1.00 1.02 1.00 1.02
Irradiated 0.87 1.31 0.23 0.77 0.73 1.52
In [40]:
grps = [col_condition, col_celltype, "Senescent_Cell"]
dff = self.rna.obs[grps].groupby(grps[:-1]).apply(
    lambda x: x["Senescent_Cell"].mean(), include_groups=False
    ).to_frame("Senescent_Cell_Burden") * 100
# kws_plot = dict(kind="violin", split=False, , common_norm=True)
kws_plot = dict(kind="box", errorbar=("ci", 95))

sns.catplot(y="Senescent_Cell_Burden", x=col_condition, **kws_plot,
            palette=palette[col_condition],
            hue=col_condition, data=dff, height=3, aspect=1.5)
sns.catplot(y="Senescent_Cell_Burden", x=col_condition, **kws_plot,
            col=col_celltype, col_wrap=4,
            palette=palette[col_condition],
            hue=col_condition, data=dff, height=3, aspect=1.5)
print("\n\n", round(dff["Senescent_Cell_Burden"].groupby(
    col_condition).describe()[["min", "25%", "50%", "75%", "max"]], 1))
print(f"\n\n\n{'=' * 80}\nPercent Cells Senescent\n{'=' * 80}")
round(100 * self.rna.obs.groupby([col_condition, col_celltype]).value_counts(
    ["Senescent_Cell_Label"], normalize=True).unstack(-1), 2)[
        "Senescent"].unstack(1)

             min  25%  50%  75%  max
Condition                          
Control     1.0  1.0  1.0  1.0  1.0
Irradiated  0.2  0.7  0.8  1.2  1.5



================================================================================
Percent Cells Senescent
================================================================================
Out[40]:
annotation_by_overlap Neuron Oligodendrocyte Astrocyte Microglial OPC Endothelial
Condition
Control 1.00 1.01 1.00 1.02 1.00 1.02
Irradiated 0.87 1.31 0.23 0.77 0.73 1.52
No description has been provided for this image
No description has been provided for this image

Differential Gene Expression¶

Mainly using edgeR

Pseudo-Bulk & Examine Covariates¶

In [42]:
pdata = scflow.tl.create_pseudobulk(
    self.rna, [i for i in [col_sample, col_condition] if i],
    "Senescent_Cell_Label_by_Type", layer="counts", mode="sum")
pdata.layers["counts"] = pdata.X.copy()
sc.pp.normalize_total(pdata, target_sum=1e6)
sc.pp.log1p(pdata)
sc.pp.pca(pdata)
sc.pl.pca(pdata, color=pdata.obs, ncols=1, size=300)
WARNING: adata.X seems to be already log-transformed.
No description has been provided for this image

Overall DEGs by Groups¶

In [50]:
%matplotlib inline

out_edgr = scflow.ax.run_deg_edgr(
    self.rna, col_condition, col_covariate=None, formula=None,
    **keys[col_condition], log2fc_thresh=0, n_top_vars=25,
    col_celltype=col_celltype, col_sample=col_sample,
    fig_title=f"{col_condition} DEGs: Overall Sample\n\n")
• Calculating NormFactors
• Estimating Dispersions
• Fitting linear model
• Calculating NormFactors
• Estimating Dispersions
• Fitting linear model
No description has been provided for this image

Snc versus Not (Group=Covariate)¶

In [44]:
# Group = Covariate
out_edgr_contrasts_snc = scflow.ax.run_deg_edgr(
    self.rna, "Senescent_Cell_Label",
    col_covariate=col_condition, formula=None,
    key_treatment="Senescent", key_control="Non-Senescent",
    log2fc_thresh=0, n_top_vars=24, xlabel_rotation=45,
    hspace=0.5, wspace=0.2, top=0.92, legend_loc="upper right",
    col_celltype=col_celltype, col_sample=col_sample)
• Calculating NormFactors
• Estimating Dispersions
• Fitting linear model
• Performing pseudobulk for paired samples
No description has been provided for this image
No description has been provided for this image

Group DEGs (SnC=Subset)¶

All Groups SnCs¶
In [47]:
out_edgr_groups_snc = scflow.ax.run_deg_edgr(
    self.rna[(self.rna.obs["Senescent_Cell_Label"] == "Senescent")],
    col_condition, **keys[col_condition], col_sample=col_sample,
    log2fc_thresh=0, n_top_vars=25, col_celltype=col_celltype)
print(list(out_edgr_groups_snc[0].variable[:25]))
out_edgr_batches_snc = out_edgr_groups_snc[0][(
    out_edgr_groups_snc[0].abs_log_fc > 1) & (
        out_edgr_groups_snc[0].adj_p_value < 0.001)].sort_values(
            "adj_p_value", ascending=True)
out_edgr_batches_top_snc = out_edgr_batches_snc.groupby("contrast").apply(
    lambda x: x.sort_values("adj_p_value", ascending=True).iloc[
        :20]).set_index("variable", append=True).reset_index(
            1, drop=True)
plt.show()
• Calculating NormFactors
• Estimating Dispersions
• Fitting linear model
• Calculating NormFactors
• Estimating Dispersions
• Fitting linear model
['Rgs5', 'Gm29260', 'Alk', 'Acta2', 'Tpm2', 'Phf21b', 'Cavin1', 'Gm12394', 'Ifitm2', 'Mideas', 'Ginm1', 'Tbx15', 'Trpc3', 'Tinagl1', 'Adgrv1', 'Slc1a4', 'Mapk8ip2', 'Zfp804b', 'Lbh', 'Gm973', 'Zfp653', 'Sec13', 'Wdr91', 'Dpysl3', 'Aldh1a3']
/tmp/ipykernel_857868/3587666276.py:10: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  out_edgr_batches_top_snc = out_edgr_batches_snc.groupby("contrast").apply(
No description has been provided for this image

SnC GEX Profiles¶

Pathway Analysis¶

In [48]:
names = gp.get_library_name()
# perts_geo = ["Aging", "Drug", "Disease"]
perts_geo = ["Aging", "Disease"]
other_sets = ["GTEx_Aging_Signatures_2021", f"HDSigDB_{species}_2021",
              "MSigDB_Hallmark_2020",  # "DGIdb_Drug_Targets_2024",
              "MSigDB_Oncogenic_Signatures", "OMIM_Disease",
              # "Reimport pdb;actome_Pathways_2024", "Reactome_2022",
              f"WikiPathways_2024_{species}", f"WikiPathways_2019_{species}"]
other_sets += [i for i in names if "GO_Biological_Process" in i]
gene_sets = dict(zip(["up", "down"], [[
    f"{u}_Perturbations_from_GEO_{i}" for u in perts_geo] + [
        f"Disease_Signatures_from_GEO_{i}_2014"] + other_sets
    for i in ["up", "down"]]))


def fx_replace_string(string):
    """Make short version of pathway terms."""
    string = re.sub("aging:([0-9]+)", "aging", re.sub(
        "([0-9]+) months v ([0-9]+) mo(nths)?", "\\1 v \\2 mo.", re.sub(
            "SRP[0-9]+ ", "", re.sub("GSE[0-9]+ ", "", string))))
    string = re.sub(".*.xlsx.", "", re.sub(
        ".*Supplementary Data ..", "", re.sub(
            "PMID([0-9])+", "", re.sub("([0-9]+) years v ([0-9]+) years",
                                       "\\1 v \\2 yrs.", string))))
    string = re.sub("Expression Of ", "", re.sub(".*.xls", "", re.sub(
        ".*.XLSX", "", re.sub(
            ".*Supplementary Table [0-9]+[-]?", "", string))))
    return string

Endrichr¶

In [59]:
out_pathway_snc_edgr_contrasts = scflow.ax.run_enrichr(
    res_rank_genes_top, col_grouping=[col_condition, col_celltype],
    gene_sets=gene_sets, fx_replace_string=fx_replace_string, title="Overall")
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/gseapy/plot.py:754: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda _x: _x.sort_values(by=self.colname).tail(self.n_terms))
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/gseapy/plot.py:754: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda _x: _x.sort_values(by=self.colname).tail(self.n_terms))
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/gseapy/plot.py:754: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda _x: _x.sort_values(by=self.colname).tail(self.n_terms))
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/gseapy/plot.py:754: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda _x: _x.sort_values(by=self.colname).tail(self.n_terms))
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/gseapy/plot.py:754: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda _x: _x.sort_values(by=self.colname).tail(self.n_terms))
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/gseapy/plot.py:754: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda _x: _x.sort_values(by=self.colname).tail(self.n_terms))
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/gseapy/plot.py:754: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda _x: _x.sort_values(by=self.colname).tail(self.n_terms))
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/gseapy/plot.py:754: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda _x: _x.sort_values(by=self.colname).tail(self.n_terms))
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/gseapy/plot.py:754: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda _x: _x.sort_values(by=self.colname).tail(self.n_terms))
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/gseapy/plot.py:754: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda _x: _x.sort_values(by=self.colname).tail(self.n_terms))
/home/easlinger/miniconda3/envs/rsc/lib/python3.13/site-packages/gseapy/plot.py:754: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda _x: _x.sort_values(by=self.colname).tail(self.n_terms))
No description has been provided for this image

SnC vs. Not¶

In [ ]:
# res_dc_ulm = scflow.ax.run_decoupler_ulm(
#         self.rna[self.rna.obs["Senescent_Cell_Label"] == "Senescent"],
#         # "Senescent_Cell_Label_by_Type",
#         # "Senescent_Cell_Label",
#         col_condition, col_condition="Senescent_Cell_Label_by_Type",
#         species=species, resource="hallmark",
#         top=0.95, hspace=1, wspace=0.5, figsize=(15, 10))

Pathway Set = Progeny¶

In [60]:
res_dc_ulm = scflow.ax.run_decoupler_ulm(
        self.rna[self.rna.obs["Senescent_Cell_Label"] == "Senescent"],
        col_condition, col_condition="Senescent_Cell_Label_by_Type",
        species=species, resource="progeny",
        hspace=0.5, wspace=0.5, top=0.95, figsize=(15, 15))
res_dc_ulm_scores = pd.concat([res_dc_ulm[0][x][1].set_index(
    "group").rename_axis(col_condition).set_index(
        "name", append=True) for x in res_dc_ulm[0]],
                              keys=res_dc_ulm[0], names=[col_celltype])
res_dc_ulm_pathways = pd.concat([pd.Series(res_dc_ulm[0][x][2])
                                 for x in res_dc_ulm[0]], keys=res_dc_ulm[0])
print(res_dc_ulm_pathways)
res_dc_ulm_scores
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
SnC Neuron           Control          [VEGF, JAK-STAT, MAPK]
                     Irradiated        [Hypoxia, NFkB, TGFb]
SnC Endothelial      Control           [p53, Estrogen, NFkB]
                     Irradiated       [Androgen, EGFR, PI3K]
SnC Oligodendrocyte  Control          [EGFR, Estrogen, MAPK]
                     Irradiated        [Hypoxia, NFkB, TGFb]
SnC Astrocyte        Control          [Estrogen, VEGF, TNFa]
                     Irradiated    [Androgen, Hypoxia, TGFb]
SnC Microglial       Control          [Estrogen, VEGF, TGFb]
                     Irradiated       [NFkB, Hypoxia, Trail]
SnC OPC              Control           [p53, TGFb, JAK-STAT]
                     Irradiated        [PI3K, Androgen, WNT]
dtype: object
Out[60]:
reference stat meanchange pval padj
annotation_by_overlap Condition name
SnC Neuron Irradiated Hypoxia rest 3.701982 0.517813 0.000299 0.004187
NFkB rest 0.979215 0.139662 0.329062 0.772141
TGFb rest 0.395513 0.081530 0.693015 0.831596
PI3K rest 0.349796 0.051773 0.726971 0.831596
Androgen rest 0.174286 0.033017 0.861870 0.861870
Control VEGF rest 3.167398 0.507750 0.001847 0.012926
JAK-STAT rest 2.198900 0.243921 0.029356 0.136994
MAPK rest 2.028440 0.316600 0.044268 0.154939
Estrogen rest 0.987773 0.147316 0.324774 0.757807
EGFR rest 0.814962 0.140238 0.416412 0.787098
Trail rest 0.757710 0.107812 0.449770 0.787098
WNT rest 0.556827 0.079187 0.578441 0.828548
TNFa rest 0.330969 0.048407 0.741124 0.828548
p53 rest 0.293715 0.062321 0.769366 0.828548
SnC Endothelial Irradiated Androgen rest 3.584758 0.741641 0.000641 0.008969
EGFR rest 3.338697 1.540799 0.001392 0.009747
PI3K rest 2.717368 0.883364 0.008397 0.039188
MAPK rest 2.048619 0.879384 0.044514 0.155801
TGFb rest 1.753021 0.685747 0.085009 0.238026
WNT rest 1.119968 0.211939 0.266831 0.622605
Trail rest 0.625223 0.133255 0.533996 0.969301
Hypoxia rest 0.497972 0.163011 0.620173 0.969301
VEGF rest 0.416077 0.140420 0.678711 0.969301
TNFa rest 0.183838 0.061991 0.854717 0.969301
JAK-STAT rest 0.034260 0.011252 0.972775 0.972775
Control p53 rest 0.084343 0.054280 0.933724 0.985383
Estrogen rest 0.082409 0.044673 0.935236 0.985383
NFkB rest 0.068369 0.041923 0.946251 0.985383
SnC Oligodendrocyte Irradiated Hypoxia rest 2.406802 0.668090 0.019425 0.222454
NFkB rest 1.396071 0.375785 0.168245 0.471085
TGFb rest 1.039007 0.306021 0.303608 0.607215
Androgen rest 0.452552 0.125401 0.652699 0.788823
TNFa rest 0.419959 0.105349 0.676134 0.788823
p53 rest 0.248027 0.096338 0.805049 0.848433
Control EGFR rest 1.898794 0.704252 0.063948 0.321328
Estrogen rest 1.739914 0.428150 0.088575 0.321328
MAPK rest 1.722135 0.541148 0.091808 0.321328
JAK-STAT rest 0.948057 0.264930 0.349181 0.699741
Trail rest 0.752802 0.151900 0.455405 0.783437
PI3K rest 0.621809 0.163893 0.537138 0.783437
VEGF rest 0.587736 0.173159 0.559598 0.783437
WNT rest 0.174686 0.047239 0.862108 0.862108
SnC Astrocyte Irradiated Androgen rest 1.679520 0.848094 0.148667 0.877616
Hypoxia rest 1.257530 0.912925 0.255683 0.877616
TGFb rest 1.102203 0.759468 0.313434 0.877616
WNT rest 0.828330 0.489239 0.446300 0.891184
PI3K rest 0.700063 0.513766 0.511612 0.891184
Trail rest 0.329130 0.284323 0.754652 0.891184
p53 rest 0.142723 0.085817 0.891184 0.891184
Control Estrogen rest 2.874783 1.045281 0.012823 0.118813
VEGF rest 1.842995 0.732380 0.081862 0.276602
TNFa rest 1.070335 0.494258 0.298867 0.523018
MAPK rest 0.454930 0.226370 0.654628 0.803295
EGFR rest 0.436221 0.234202 0.667864 0.803295
JAK-STAT rest 0.406921 0.195622 0.688892 0.803295
NFkB rest 0.329432 0.129615 0.745917 0.803295
SnC Microglial Irradiated NFkB rest 0.478197 0.210434 0.639837 0.990310
Hypoxia rest 0.127917 0.075512 0.899757 0.990310
Trail rest 0.085560 0.035579 0.932761 0.990310
Control Estrogen rest 2.014544 0.889689 0.062811 0.561119
VEGF rest 1.856365 1.148468 0.080160 0.561119
TGFb rest 0.930479 0.356076 0.364729 0.990310
MAPK rest 0.759307 0.549344 0.457522 0.990310
Androgen rest 0.744521 0.201530 0.466342 0.990310
TNFa rest 0.743269 0.323573 0.468504 0.990310
EGFR rest 0.524796 0.375646 0.606333 0.990310
WNT rest 0.329964 0.123749 0.745593 0.990310
PI3K rest 0.224400 0.095042 0.825044 0.990310
p53 rest 0.016785 0.008812 0.986794 0.990310
JAK-STAT rest 0.012315 0.005595 0.990310 0.990310
SnC OPC Irradiated PI3K rest 0.939689 0.444774 0.366475 0.755626
Androgen rest 0.602369 0.376804 0.558447 0.755626
WNT rest 0.514886 0.224269 0.615816 0.755626
Hypoxia rest 0.319025 0.117628 0.754560 0.803744
Control p53 rest 2.225798 1.162255 0.050217 0.703036
TGFb rest 1.729076 0.887085 0.114639 0.802476
JAK-STAT rest 1.165614 0.409402 0.271726 0.810201
NFkB rest 0.901605 0.465332 0.388931 0.810201
MAPK rest 0.749271 0.294694 0.471091 0.810201
Trail rest 0.709650 0.522678 0.494847 0.810201
Estrogen rest 0.614113 0.373072 0.554446 0.810201
EGFR rest 0.458400 0.198016 0.657231 0.810201
TNFa rest 0.404672 0.167259 0.694458 0.810201
VEGF rest 0.219362 0.157173 0.830810 0.830810

Pathway Set = Hallmark¶

In [61]:
res_dc_ulm_hm = scflow.ax.run_decoupler_ulm(
        self.rna[self.rna.obs["Senescent_Cell_Label"] == "Senescent"],
        col_condition, col_condition="Senescent_Cell_Label_by_Type",
        species=species, resource="hallmark",
        hspace=0.5, top=0.95, figsize=(15, 15))
res_dc_ulm_hm_scores = pd.concat([res_dc_ulm_hm[0][x][1].set_index(
    "group").rename_axis(col_condition).set_index(
        "name", append=True) for x in res_dc_ulm_hm[0]],
                                 keys=res_dc_ulm_hm[0], names=[col_celltype])
res_dc_ulm_hm_scores
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
Out[61]:
reference stat meanchange pval padj
annotation_by_overlap Condition name
SnC Neuron Irradiated KRAS_SIGNALING_UP rest 2.142576 0.364921 0.033719 0.745641
PI3K_AKT_MTOR_SIGNALING rest 1.808917 0.293497 0.072443 0.745641
IL2_STAT5_SIGNALING rest 1.737617 0.261750 0.084334 0.745641
HYPOXIA rest 1.716823 0.255888 0.088029 0.745641
KRAS_SIGNALING_DN rest 1.522388 0.298502 0.129973 0.745641
APOPTOSIS rest 1.520384 0.230356 0.130511 0.745641
APICAL_SURFACE rest 1.287556 0.202346 0.199834 0.810858
MYOGENESIS rest 1.170915 0.221932 0.243460 0.810858
TGF_BETA_SIGNALING rest 1.163868 0.187855 0.246400 0.810858
UV_RESPONSE_DN rest 1.110060 0.271976 0.268713 0.810858
REACTIVE_OXYGEN_SPECIES_PATHWAY rest 1.093943 0.163808 0.275692 0.810858
INFLAMMATORY_RESPONSE rest 0.951246 0.170875 0.342970 0.866892
UV_RESPONSE_UP rest 0.912739 0.121487 0.362892 0.866892
SPERMATOGENESIS rest 0.779272 0.135292 0.437104 0.866892
ALLOGRAFT_REJECTION rest 0.756070 0.110154 0.450784 0.866892
APICAL_JUNCTION rest 0.563461 0.093268 0.573947 0.956493
FATTY_ACID_METABOLISM rest 0.489640 0.068687 0.625111 0.976737
MITOTIC_SPINDLE rest 0.358345 0.067090 0.720578 0.983385
PROTEIN_SECRETION rest 0.283355 0.047455 0.777287 0.983385
ESTROGEN_RESPONSE_LATE rest 0.249911 0.034203 0.802991 0.983385
HEDGEHOG_SIGNALING rest 0.159255 0.027786 0.873681 0.983385
INTERFERON_ALPHA_RESPONSE rest 0.154764 0.017483 0.877211 0.983385
CHOLESTEROL_HOMEOSTASIS rest 0.053349 0.008544 0.957523 0.983385
GLYCOLYSIS rest 0.045131 0.005911 0.964061 0.983385
Control NOTCH_SIGNALING rest 2.271308 0.328389 0.024601 0.718386
UNFOLDED_PROTEIN_RESPONSE rest 1.583880 0.216317 0.115275 0.718386
OXIDATIVE_PHOSPHORYLATION rest 1.525177 0.276239 0.129309 0.718386
BILE_ACID_METABOLISM rest 1.422067 0.177724 0.157028 0.785141
MYC_TARGETS_V2 rest 1.232390 0.113865 0.219729 0.792944
HEME_METABOLISM rest 1.226717 0.181348 0.221754 0.792944
IL6_JAK_STAT3_SIGNALING rest 0.918259 0.115305 0.359940 0.855803
G2M_CHECKPOINT rest 0.897914 0.157923 0.370601 0.855803
COAGULATION rest 0.874475 0.117031 0.383190 0.855803
E2F_TARGETS rest 0.854995 0.111235 0.393849 0.855803
PEROXISOME rest 0.790446 0.112579 0.430469 0.855803
DNA_REPAIR rest 0.657605 0.082781 0.511749 0.947684
WNT_BETA_CATENIN_SIGNALING rest 0.577639 0.077672 0.564360 0.948886
ANDROGEN_RESPONSE rest 0.545305 0.074111 0.586313 0.948886
COMPLEMENT rest 0.542397 0.077462 0.588309 0.948886
PANCREAS_BETA_CELLS rest 0.463600 0.079492 0.643575 0.975113
MTORC1_SIGNALING rest 0.262754 0.039930 0.793092 0.983172
ADIPOGENESIS rest 0.241556 0.035389 0.809438 0.983172
ESTROGEN_RESPONSE_EARLY rest 0.208972 0.035283 0.834745 0.983172
P53_PATHWAY rest 0.088468 0.010999 0.929628 0.983172
XENOBIOTIC_METABOLISM rest 0.082153 0.011234 0.934630 0.983172
ANGIOGENESIS rest 0.079310 0.013479 0.936888 0.983172
EPITHELIAL_MESENCHYMAL_TRANSITION rest 0.073206 0.010779 0.941735 0.983172
TNFA_SIGNALING_VIA_NFKB rest 0.041060 0.005537 0.967300 0.983172
MYC_TARGETS_V1 rest 0.032318 0.005219 0.974259 0.983172
INTERFERON_GAMMA_RESPONSE rest 0.021126 0.002829 0.983172 0.983172
SnC Endothelial Irradiated PI3K_AKT_MTOR_SIGNALING rest 3.159266 0.859738 0.002484 0.066033
PEROXISOME rest 2.931681 0.564267 0.004629 0.066033
ADIPOGENESIS rest 2.930790 0.755655 0.004863 0.066033
REACTIVE_OXYGEN_SPECIES_PATHWAY rest 2.856794 0.563219 0.006110 0.066033
CHOLESTEROL_HOMEOSTASIS rest 2.819205 0.593735 0.006603 0.066033
P53_PATHWAY rest 2.622386 0.702870 0.011158 0.092982
MTORC1_SIGNALING rest 2.490442 0.614772 0.015690 0.102771
ESTROGEN_RESPONSE_LATE rest 2.464852 0.597150 0.016443 0.102771
WNT_BETA_CATENIN_SIGNALING rest 2.351715 0.603872 0.021782 0.116286
COAGULATION rest 2.317253 0.664276 0.023672 0.116286
MYC_TARGETS_V1 rest 2.312655 0.765115 0.025583 0.116286
TGF_BETA_SIGNALING rest 2.206153 0.922724 0.030924 0.128680
KRAS_SIGNALING_DN rest 2.185033 0.495850 0.033457 0.128680
MYOGENESIS rest 1.869150 0.785457 0.068118 0.241562
IL6_JAK_STAT3_SIGNALING rest 1.808278 0.400508 0.076282 0.241562
IL2_STAT5_SIGNALING rest 1.794582 0.519364 0.077300 0.241562
E2F_TARGETS rest 1.620357 0.339379 0.110623 0.307285
HYPOXIA rest 1.542211 0.484102 0.128231 0.337450
APICAL_JUNCTION rest 1.514714 0.650237 0.135013 0.337533
XENOBIOTIC_METABOLISM rest 1.352415 0.336287 0.181376 0.394296
ALLOGRAFT_REJECTION rest 1.101142 0.236069 0.274851 0.528560
ANDROGEN_RESPONSE rest 1.005321 0.312356 0.318528 0.589866
ESTROGEN_RESPONSE_EARLY rest 0.813877 0.187435 0.418686 0.697810
UNFOLDED_PROTEIN_RESPONSE rest 0.684091 0.157426 0.497131 0.776767
TNFA_SIGNALING_VIA_NFKB rest 0.578890 0.221815 0.564707 0.794557
OXIDATIVE_PHOSPHORYLATION rest 0.579060 0.232394 0.564755 0.794557
APOPTOSIS rest 0.497410 0.133760 0.621464 0.817715
ANGIOGENESIS rest 0.419531 0.105779 0.676609 0.832794
HEME_METABOLISM rest 0.410443 0.103299 0.682891 0.832794
INFLAMMATORY_RESPONSE rest 0.349040 0.096517 0.728187 0.866889
UV_RESPONSE_UP rest 0.196583 0.049065 0.844888 0.960100
EPITHELIAL_MESENCHYMAL_TRANSITION rest 0.023175 0.012782 0.981587 0.998487
MITOTIC_SPINDLE rest 0.019778 0.008934 0.984281 0.998487
G2M_CHECKPOINT rest 0.001903 0.000560 0.998487 0.998487
Control DNA_REPAIR rest 0.894136 0.268374 0.383328 0.999188
BILE_ACID_METABOLISM rest 0.804000 0.311218 0.431998 0.999188
FATTY_ACID_METABOLISM rest 0.759612 0.309940 0.457679 0.999188
KRAS_SIGNALING_UP rest 0.688868 0.361831 0.500729 0.999188
PANCREAS_BETA_CELLS rest 0.626542 0.339745 0.538914 0.999188
GLYCOLYSIS rest 0.519873 0.251100 0.609548 0.999188
APICAL_SURFACE rest 0.511467 0.221744 0.615271 0.999188
COMPLEMENT rest 0.384936 0.205921 0.705387 0.999188
INTERFERON_GAMMA_RESPONSE rest 0.317091 0.162176 0.754869 0.999188
MYC_TARGETS_V2 rest 0.308436 0.086652 0.762401 0.999188
HEDGEHOG_SIGNALING rest 0.272183 0.115235 0.788693 0.999188
NOTCH_SIGNALING rest 0.251603 0.141116 0.804568 0.999188
PROTEIN_SECRETION rest 0.162873 0.102249 0.872455 0.999188
INTERFERON_ALPHA_RESPONSE rest 0.054549 0.026627 0.957099 0.999188
UV_RESPONSE_DN rest 0.052908 0.046496 0.958402 0.999188
SPERMATOGENESIS rest 0.013561 0.005308 0.989329 0.999188
SnC Oligodendrocyte Irradiated P53_PATHWAY rest 2.765623 0.633356 0.007716 0.192895
IL2_STAT5_SIGNALING rest 2.038914 0.440643 0.046424 0.386868
UV_RESPONSE_DN rest 1.936816 0.610635 0.058042 0.414588
TGF_BETA_SIGNALING rest 1.503208 0.440894 0.138575 0.600070
WNT_BETA_CATENIN_SIGNALING rest 0.947459 0.236270 0.347652 0.973782
MYC_TARGETS_V1 rest 0.671746 0.143114 0.504731 0.973782
APICAL_JUNCTION rest 0.595061 0.141348 0.554620 0.973782
SPERMATOGENESIS rest 0.533479 0.126417 0.595821 0.973782
NOTCH_SIGNALING rest 0.512299 0.116688 0.610457 0.973782
TNFA_SIGNALING_VIA_NFKB rest 0.487565 0.119417 0.628136 0.973782
REACTIVE_OXYGEN_SPECIES_PATHWAY rest 0.397188 0.092868 0.692751 0.973782
ESTROGEN_RESPONSE_EARLY rest 0.390704 0.092843 0.697501 0.973782
PROTEIN_SECRETION rest 0.285650 0.088770 0.776251 0.973782
ANDROGEN_RESPONSE rest 0.241534 0.050096 0.810054 0.973782
COMPLEMENT rest 0.237432 0.071822 0.813221 0.973782
HEME_METABOLISM rest 0.205916 0.065813 0.837632 0.973782
MYC_TARGETS_V2 rest 0.125705 0.021895 0.900425 0.973782
APOPTOSIS rest 0.101225 0.022798 0.919735 0.973782
HYPOXIA rest 0.007834 0.001760 0.993780 0.996603
Control OXIDATIVE_PHOSPHORYLATION rest 3.361479 0.685283 0.001569 0.078428
ADIPOGENESIS rest 2.210179 0.459587 0.032109 0.482342
IL6_JAK_STAT3_SIGNALING rest 2.130031 0.418337 0.038587 0.482342
UNFOLDED_PROTEIN_RESPONSE rest 1.858510 0.434352 0.069556 0.586266
MTORC1_SIGNALING rest 1.589528 0.502654 0.118802 0.669280
PI3K_AKT_MTOR_SIGNALING rest 1.584229 0.377896 0.120470 0.669280
CHOLESTEROL_HOMEOSTASIS rest 1.346078 0.433487 0.185574 0.752557
BILE_ACID_METABOLISM rest 1.326447 0.284397 0.191240 0.752557
PEROXISOME rest 1.308649 0.274598 0.197348 0.752557
E2F_TARGETS rest 1.269688 0.323460 0.210716 0.752557
FATTY_ACID_METABOLISM rest 1.149083 0.333270 0.256502 0.840020
INFLAMMATORY_RESPONSE rest 1.119930 0.367422 0.268806 0.840020
GLYCOLYSIS rest 0.766006 0.201997 0.447656 0.979959
DNA_REPAIR rest 0.766995 0.182668 0.448039 0.979959
INTERFERON_GAMMA_RESPONSE rest 0.680492 0.191404 0.500049 0.979959
ESTROGEN_RESPONSE_LATE rest 0.616426 0.151797 0.540768 0.979959
KRAS_SIGNALING_UP rest 0.542869 0.164097 0.589909 0.979959
G2M_CHECKPOINT rest 0.498441 0.151160 0.620680 0.979959
KRAS_SIGNALING_DN rest 0.451347 0.143161 0.653967 0.979959
PANCREAS_BETA_CELLS rest 0.404676 0.104688 0.687594 0.979959
APICAL_SURFACE rest 0.390234 0.143332 0.698262 0.979959
INTERFERON_ALPHA_RESPONSE rest 0.369237 0.093058 0.713786 0.979959
HEDGEHOG_SIGNALING rest 0.298063 0.101574 0.767026 0.979959
XENOBIOTIC_METABOLISM rest 0.294339 0.072146 0.769831 0.979959
COAGULATION rest 0.263189 0.071259 0.793591 0.979959
ANGIOGENESIS rest 0.249998 0.082305 0.803716 0.979959
UV_RESPONSE_UP rest 0.157934 0.033212 0.875200 0.979959
MITOTIC_SPINDLE rest 0.124844 0.036643 0.901200 0.979959
MYOGENESIS rest 0.098542 0.030151 0.921941 0.979959
EPITHELIAL_MESENCHYMAL_TRANSITION rest 0.074724 0.017994 0.940761 0.979959
ALLOGRAFT_REJECTION rest 0.003891 0.001053 0.996913 0.996913
SnC Astrocyte Irradiated OXIDATIVE_PHOSPHORYLATION rest 2.400231 1.072705 0.053650 0.915136
INTERFERON_GAMMA_RESPONSE rest 2.205333 1.432285 0.071805 0.915136
ESTROGEN_RESPONSE_EARLY rest 1.799930 0.880359 0.124718 0.915136
HEDGEHOG_SIGNALING rest 1.659226 1.295639 0.149931 0.915136
MYOGENESIS rest 1.523771 1.464240 0.186906 0.915136
PROTEIN_SECRETION rest 1.288316 1.064067 0.246321 0.915136
CHOLESTEROL_HOMEOSTASIS rest 1.138799 1.175786 0.304181 0.915136
INFLAMMATORY_RESPONSE rest 1.061977 0.825675 0.330933 0.915136
HYPOXIA rest 0.985663 0.964715 0.363082 0.915136
KRAS_SIGNALING_UP rest 0.999065 0.782842 0.367641 0.915136
APICAL_JUNCTION rest 1.025267 0.702682 0.375686 0.915136
ESTROGEN_RESPONSE_LATE rest 0.925298 0.646151 0.394889 0.915136
UV_RESPONSE_UP rest 0.926967 0.533047 0.396836 0.915136
WNT_BETA_CATENIN_SIGNALING rest 0.864687 0.722630 0.426092 0.915136
PI3K_AKT_MTOR_SIGNALING rest 0.790049 0.583760 0.462266 0.915136
UV_RESPONSE_DN rest 0.722294 0.719450 0.499446 0.915136
APOPTOSIS rest 0.716384 0.693672 0.502629 0.915136
MTORC1_SIGNALING rest 0.703036 0.739993 0.509405 0.915136
MYC_TARGETS_V2 rest 0.678498 0.400628 0.522920 0.915136
IL2_STAT5_SIGNALING rest 0.639502 0.369441 0.546157 0.915136
ADIPOGENESIS rest 0.585143 0.364398 0.579781 0.915136
GLYCOLYSIS rest 0.592815 0.407551 0.581918 0.915136
REACTIVE_OXYGEN_SPECIES_PATHWAY rest 0.507714 0.370154 0.629911 0.915136
ANDROGEN_RESPONSE rest 0.407698 0.360032 0.698459 0.915136
APICAL_SURFACE rest 0.394738 0.356774 0.714368 0.915136
HEME_METABOLISM rest 0.329132 0.283897 0.755230 0.915136
COAGULATION rest 0.312676 0.220062 0.766563 0.915136
FATTY_ACID_METABOLISM rest 0.287908 0.180006 0.789307 0.915136
XENOBIOTIC_METABOLISM rest 0.278536 0.179241 0.789998 0.915136
NOTCH_SIGNALING rest 0.275181 0.173452 0.792990 0.915136
TNFA_SIGNALING_VIA_NFKB rest 0.270227 0.157867 0.796771 0.915136
ANGIOGENESIS rest 0.259804 0.174602 0.805619 0.915136
MITOTIC_SPINDLE rest 0.240880 0.202192 0.823623 0.915136
PEROXISOME rest 0.082136 0.037789 0.938242 0.960966
ALLOGRAFT_REJECTION rest 0.076330 0.053297 0.941747 0.960966
Control IL6_JAK_STAT3_SIGNALING rest 3.961398 0.565809 0.001501 0.037532
INTERFERON_ALPHA_RESPONSE rest 2.130330 0.802666 0.049471 0.353368
PANCREAS_BETA_CELLS rest 1.790613 0.840845 0.093829 0.413769
G2M_CHECKPOINT rest 1.611372 0.820194 0.124676 0.413769
P53_PATHWAY rest 1.576037 0.554961 0.132460 0.413769
MYC_TARGETS_V1 rest 1.585713 0.720010 0.140681 0.413769
E2F_TARGETS rest 1.296179 0.463819 0.225429 0.520622
SPERMATOGENESIS rest 1.200751 0.640054 0.245420 0.533522
DNA_REPAIR rest 0.902404 0.322760 0.380051 0.612985
COMPLEMENT rest 0.760255 0.232695 0.462014 0.700022
BILE_ACID_METABOLISM rest 0.714134 0.280526 0.484835 0.712993
TGF_BETA_SIGNALING rest 0.574772 0.210211 0.578137 0.780885
UNFOLDED_PROTEIN_RESPONSE rest 0.216148 0.066644 0.831337 0.903628
KRAS_SIGNALING_DN rest 0.155676 0.049374 0.878021 0.923811
EPITHELIAL_MESENCHYMAL_TRANSITION rest 0.050068 0.026098 0.960620 0.960620
SnC Microglial Irradiated ANGIOGENESIS rest 1.883671 0.803948 0.080596 0.864863
UNFOLDED_PROTEIN_RESPONSE rest 1.638420 0.750745 0.121800 0.864863
ADIPOGENESIS rest 1.386754 0.553775 0.182874 0.864863
SPERMATOGENESIS rest 1.268677 0.599289 0.220864 0.864863
NOTCH_SIGNALING rest 1.177634 0.745932 0.255067 0.864863
OXIDATIVE_PHOSPHORYLATION rest 1.134618 0.302260 0.271457 0.864863
KRAS_SIGNALING_DN rest 1.112222 0.602748 0.284494 0.864863
HEDGEHOG_SIGNALING rest 0.885356 0.349359 0.393138 0.864863
COAGULATION rest 0.812371 0.290474 0.427625 0.864863
APICAL_JUNCTION rest 0.733883 0.368603 0.474979 0.864863
WNT_BETA_CATENIN_SIGNALING rest 0.677483 0.290341 0.507098 0.864863
UV_RESPONSE_DN rest 0.674778 0.399796 0.508940 0.864863
ANDROGEN_RESPONSE rest 0.528186 0.215489 0.603856 0.864863
HYPOXIA rest 0.519903 0.279685 0.609717 0.864863
TNFA_SIGNALING_VIA_NFKB rest 0.463192 0.188081 0.649634 0.864863
IL2_STAT5_SIGNALING rest 0.443425 0.200150 0.662744 0.864863
MYC_TARGETS_V2 rest 0.409986 0.175426 0.687303 0.864863
APOPTOSIS rest 0.379646 0.175467 0.709188 0.864863
COMPLEMENT rest 0.291706 0.121456 0.773956 0.879496
MYOGENESIS rest 0.211513 0.078436 0.834981 0.907588
P53_PATHWAY rest 0.186591 0.087924 0.854252 0.908779
TGF_BETA_SIGNALING rest 0.153111 0.100636 0.880129 0.916801
MTORC1_SIGNALING rest 0.080843 0.037904 0.936480 0.937460
Control ESTROGEN_RESPONSE_LATE rest 2.552047 0.775144 0.020017 0.645666
E2F_TARGETS rest 2.430024 1.042437 0.025827 0.645666
REACTIVE_OXYGEN_SPECIES_PATHWAY rest 1.725756 0.557379 0.101728 0.864863
G2M_CHECKPOINT rest 1.654172 0.740509 0.116090 0.864863
PEROXISOME rest 1.569311 0.609296 0.136845 0.864863
APICAL_SURFACE rest 1.456317 0.663802 0.162755 0.864863
INFLAMMATORY_RESPONSE rest 1.369762 0.501127 0.193531 0.864863
GLYCOLYSIS rest 1.128819 0.428617 0.274119 0.864863
INTERFERON_ALPHA_RESPONSE rest 1.089570 0.439384 0.290292 0.864863
FATTY_ACID_METABOLISM rest 1.051590 0.483941 0.307154 0.864863
MYC_TARGETS_V1 rest 0.986605 0.361961 0.337962 0.864863
XENOBIOTIC_METABOLISM rest 0.975281 0.420361 0.344681 0.864863
PI3K_AKT_MTOR_SIGNALING rest 0.858077 0.430923 0.402158 0.864863
IL6_JAK_STAT3_SIGNALING rest 0.838620 0.357743 0.412937 0.864863
HEME_METABOLISM rest 0.773055 0.321244 0.450330 0.864863
UV_RESPONSE_UP rest 0.718465 0.363887 0.481696 0.864863
PANCREAS_BETA_CELLS rest 0.589180 0.244604 0.563205 0.864863
INTERFERON_GAMMA_RESPONSE rest 0.564040 0.248199 0.580894 0.864863
DNA_REPAIR rest 0.553911 0.152134 0.586563 0.864863
CHOLESTEROL_HOMEOSTASIS rest 0.488309 0.217069 0.631350 0.864863
ALLOGRAFT_REJECTION rest 0.473309 0.259639 0.641947 0.864863
EPITHELIAL_MESENCHYMAL_TRANSITION rest 0.408186 0.268612 0.687952 0.864863
BILE_ACID_METABOLISM rest 0.392144 0.156487 0.699564 0.864863
PROTEIN_SECRETION rest 0.350763 0.141727 0.730227 0.864979
ESTROGEN_RESPONSE_EARLY rest 0.332773 0.137360 0.743882 0.864979
MITOTIC_SPINDLE rest 0.214941 0.123275 0.833344 0.907588
KRAS_SIGNALING_UP rest 0.079577 0.036261 0.937460 0.937460
SnC OPC Irradiated ANGIOGENESIS rest 2.869110 0.896150 0.013972 0.291543
PROTEIN_SECRETION rest 2.909850 1.208348 0.014425 0.291543
EPITHELIAL_MESENCHYMAL_TRANSITION rest 2.487000 1.153057 0.027505 0.291543
UNFOLDED_PROTEIN_RESPONSE rest 2.215226 0.776301 0.045322 0.291543
MYOGENESIS rest 2.194868 1.288903 0.045912 0.291543
OXIDATIVE_PHOSPHORYLATION rest 2.196262 0.913177 0.046647 0.291543
MYC_TARGETS_V2 rest 2.166675 0.819943 0.053158 0.295325
APOPTOSIS rest 1.931909 0.459181 0.074155 0.349487
UV_RESPONSE_DN rest 1.922804 0.972273 0.078129 0.349487
G2M_CHECKPOINT rest 1.828013 1.034153 0.090867 0.349487
PEROXISOME rest 1.320796 0.631230 0.209704 0.630631
BILE_ACID_METABOLISM rest 1.322527 0.704785 0.214415 0.630631
APICAL_SURFACE rest 1.105825 0.439868 0.298826 0.679493
PANCREAS_BETA_CELLS rest 1.049321 0.461365 0.311834 0.679493
GLYCOLYSIS rest 0.922720 0.523047 0.372877 0.709357
HYPOXIA rest 0.829432 0.298163 0.421169 0.709357
UV_RESPONSE_UP rest 0.826586 0.471638 0.425614 0.709357
ANDROGEN_RESPONSE rest 0.738070 0.187426 0.474043 0.740692
MYC_TARGETS_V1 rest 0.513848 0.267042 0.615766 0.855231
PI3K_AKT_MTOR_SIGNALING rest 0.446299 0.203471 0.662322 0.866075
ADIPOGENESIS rest 0.240811 0.114240 0.815128 0.915670
ALLOGRAFT_REJECTION rest 0.202663 0.115402 0.842416 0.915670
INTERFERON_GAMMA_RESPONSE rest 0.166380 0.072639 0.870944 0.926536
ESTROGEN_RESPONSE_EARLY rest 0.066603 0.033665 0.947900 0.967245
Control IL2_STAT5_SIGNALING rest 2.210695 1.053162 0.057591 0.545735
MTORC1_SIGNALING rest 1.940537 0.705264 0.083112 0.545735
FATTY_ACID_METABOLISM rest 1.592292 1.006582 0.145624 0.566254
DNA_REPAIR rest 1.210743 0.684809 0.254403 0.826562
CHOLESTEROL_HOMEOSTASIS rest 1.140331 0.480877 0.283818 0.826562
COMPLEMENT rest 1.114198 0.636481 0.304184 0.826562
IL6_JAK_STAT3_SIGNALING rest 1.061215 0.764406 0.319335 0.826562
HEDGEHOG_SIGNALING rest 1.006973 0.686090 0.338848 0.826562
KRAS_SIGNALING_DN rest 0.908116 0.526568 0.385704 0.826562
E2F_TARGETS rest 0.794504 0.465200 0.450880 0.826562
TNFA_SIGNALING_VIA_NFKB rest 0.787249 0.407241 0.459098 0.826562
MITOTIC_SPINDLE rest 0.721036 0.488457 0.487909 0.826562
TGF_BETA_SIGNALING rest 0.728797 0.472072 0.495937 0.826562
WNT_BETA_CATENIN_SIGNALING rest 0.663398 0.431954 0.522150 0.841692
P53_PATHWAY rest 0.516317 0.294691 0.617215 0.917709
NOTCH_SIGNALING rest 0.486103 0.337436 0.637370 0.917709
XENOBIOTIC_METABOLISM rest 0.475324 0.248612 0.644924 0.917709
COAGULATION rest 0.386195 0.227766 0.707459 0.917709
INTERFERON_ALPHA_RESPONSE rest 0.370159 0.154902 0.719425 0.917709
KRAS_SIGNALING_UP rest 0.349219 0.184954 0.734167 0.917709
APICAL_JUNCTION rest 0.321967 0.181526 0.754444 0.920054
ESTROGEN_RESPONSE_LATE rest 0.239644 0.141372 0.815601 0.939460
REACTIVE_OXYGEN_SPECIES_PATHWAY rest 0.233614 0.174086 0.820025 0.939460
INFLAMMATORY_RESPONSE rest 0.180719 0.082878 0.861576 0.939460
HEME_METABOLISM rest 0.115375 0.061138 0.910467 0.948404
SPERMATOGENESIS rest 0.007319 0.005110 0.994317 0.994317

Individual Cell Scores¶

In [63]:
cvod = ["Senescent_Cell_Label_by_Type",
        "Senescent_Cell_Label_by_Type", col_condition]
res_aucell = scflow.ax.run_decoupler_aucell(
    self.rna, col_covariates=cvod,
    resource="progeny", species=species, inplace=True)
_ = self.plot(genes=list(self.rna.obsm["score_aucell"].columns),
              subset=self.rna.obs["Senescent_Cell"],
              col_celltype=col_condition, kind="violin",
              by_group="Senescent_Cell_Label_by_Type",
              figsize=(15, 15))
2025-09-04 14:47:24 | [INFO] aucell - Running aucell
2025-09-04 14:47:24 | [INFO] Extracted omics mat with 31446 rows (observations) and 23253 columns (features)
2025-09-04 14:47:24 | [INFO] Network has 14771 unique features and 14 unique sources
2025-09-04 14:47:24 | [INFO] aucell - calculating 14 AUCs for 23253 targets across 31446 observations, categorizing features at rank=1163
  0%|          | 0/31446 [00:00<?, ?it/s]
2025-09-04 14:47:35 | [INFO] aucell - done
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image

Plot¶

In [142]:
ggg
Out[142]:
{'Control': {'Neuron': ['Nrg1', 'Iqgap2', 'Ctsb', 'Hmgb1', 'Cd9'],
  'Oligodendrocyte': ['Cd9', 'Nrg1', 'Rps6ka5', 'Il18', 'Ctsb'],
  'Astrocyte': ['Igfbp5', 'Nrg1', 'Serpine2', 'Bmp6', 'Cd9'],
  'Microglial': ['Serpine2', 'Selplg', 'Nrg1', 'Ctsb', 'Cd9'],
  'OPC': ['Nrg1', 'Serpine2', 'Cd9', 'Ctnnb1', 'Il18'],
  'Endothelial': ['Kitl', 'Cxcl12', 'Igfbp7', 'Pecam1', 'Jun']},
 'Irradiated': {'Neuron': ['Nrg1', 'Hmgb1', 'Ctnnb1', 'Rps6ka5', 'Iqgap2'],
  'Oligodendrocyte': ['Nrg1', 'Cd9', 'Rps6ka5', 'Fgf1', 'Timp2'],
  'Astrocyte': ['Rps6ka5', 'Ctnnb1', 'Nrg1', 'Ctsb', 'Il18'],
  'Microglial': ['Nrg1', 'Ctsb', 'Selplg', 'Lcp1', 'Rps6ka5'],
  'OPC': ['Serpine2', 'Nrg1', 'Cd9', 'Nap1l4', 'Rps6ka5'],
  'Endothelial': ['Igfbp7', 'Nrg1', 'Kitl', 'Cxcl12', 'Il6st']}}
In [167]:
# Mask for High Senescence Subset & Helper Variable for Figure Dimensions
subset = self.rna.obs["Senescent_Cell"].isin([1, True])
num_cts = len(self.rna[subset].obs[col_celltype].unique())

# Get Top-Expressed Senescence Genes in SnCs
gex_sncs = sc.get.obs_df(self.rna[subset], genes).join(
    self.rna[subset].obs[[col_condition, col_celltype]])
gex_sncs_means = gex_sncs.groupby([col_condition, col_celltype]).mean()
ggg = gex_sncs_means.stack().groupby([
    col_condition, col_celltype]).apply(
        lambda x: list(x.sort_values(ascending=False).loc[
            x.name].index.values[:5]))
grps = ggg.reset_index()[col_condition].unique()
ggg = dict(zip(grps, [dict(ggg.loc[x]) for x in grps]))
ggg_collapsed = dict(pd.DataFrame(ggg).apply(lambda x: list(np.unique(
    x.iloc[0] + x.iloc[1])), axis=1))
gex_sncs_means_agg = gex_sncs.groupby(col_condition).apply(
    lambda x: x.drop(col_celltype, axis=1).mean())
ggg_collapsed_ct = gex_sncs_means_agg.stack().groupby([
    col_condition]).apply(lambda x: list(x.sort_values(ascending=False).loc[
        x.name].index.values[:10]))

# Overall
_ = self.plot(kind="matrix", genes=list(ggg_collapsed_ct.explode().unique()),
              col_celltype=col_condition, layer="log1p",
              subset=subset, dendrogram=True, swap_axes=False,
              standard_scale="var", title="Overall")

# Plot Most Highly-Expressed Genes in Each Senescent Cell Type
for x in grps:
    subsg = (subset) & (self.rna.obs[col_condition] == x)
    gsubs = set(ggg[x].keys()).intersection(self.rna.obs[subsg][
        col_celltype].unique())
    gsubs = dict(zip(gsubs, [ggg[x][i] for i in gsubs]))
    _ = self.plot(kind="matrix", genes=gsubs,
                  col_celltype=col_celltype, layer="log1p",
                  subset=subsg, dendrogram=True, swap_axes=False,
                  standard_scale="var", title=x)
WARNING: Dendrogram not added. Dendrogram is added only when the number of categories to plot > 2
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image

Write Object¶

In [ ]:
# Send Email with Output When Done
if email is not None and html_out is not None:
    os.system(f"jupyter nbconvert --to html {cur_file}")
    os.system(f"echo 'yay' | mutt -s 'JOB DONE' -a {html_out} -- {email}")

if overwrite is True or os.path.exists() is False:
    self.rna.write_h5ad(file_path_new)
else:
    print(f"\n\n\n{'=' * 120}\nOVERWRITE IS FALSE..."
          f"NOT WRITING OBJECT!!!\n{'=' * 120}\n\n\n")